Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: src/trusted/debug_stub/nacl_debug.cc

Issue 206493005: Provide chrome the option of learning the debug stub port chosen by nacl. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: review fixes Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/public/chrome_main.h ('k') | src/trusted/debug_stub/transport.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 7
8 #include <vector> 8 #include <vector>
9 #include <map> 9 #include <map>
10 10
(...skipping 29 matching lines...) Expand all
40 #pragma warning(disable:4530) 40 #pragma warning(disable:4530)
41 #endif 41 #endif
42 42
43 43
44 static Target *g_target = NULL; 44 static Target *g_target = NULL;
45 static SocketBinding *g_socket_binding = NULL; 45 static SocketBinding *g_socket_binding = NULL;
46 46
47 int NaClDebugBindSocket() { 47 int NaClDebugBindSocket() {
48 if (g_socket_binding == NULL) { 48 if (g_socket_binding == NULL) {
49 NaClDebugStubInit(); 49 NaClDebugStubInit();
50 const char *addr = "127.0.0.1:4014"; 50 // Try port 4014 first for compatibility.
51 g_socket_binding = SocketBinding::Bind(addr); 51 g_socket_binding = SocketBinding::Bind("127.0.0.1:4014");
52 // If port 4014 is not available, try any port.
52 if (g_socket_binding == NULL) { 53 if (g_socket_binding == NULL) {
53 NaClLog(LOG_ERROR, "NaClStubThread: Failed to bind TCP port '%s'\n", 54 g_socket_binding = SocketBinding::Bind("127.0.0.1:0");
54 addr); 55 }
56 if (g_socket_binding == NULL) {
57 NaClLog(LOG_ERROR,
58 "NaClDebugStubBindSocket: Failed to bind any TCP port\n");
55 return 0; 59 return 0;
56 } 60 }
57 NaClLog(LOG_WARNING, 61 NaClLog(LOG_WARNING,
58 "nacl_debug(%d) : Connect GDB with 'target remote %s'.\n", 62 "nacl_debug(%d) : Connect GDB with 'target remote :%d\n",
59 __LINE__, addr); 63 __LINE__, g_socket_binding->GetBoundPort());
60 } 64 }
61 return 1; 65 return 1;
62 } 66 }
63 67
64 void NaClDebugSetBoundSocket(NaClSocketHandle bound_socket) { 68 void NaClDebugSetBoundSocket(NaClSocketHandle bound_socket) {
65 CHECK(g_socket_binding == NULL); 69 CHECK(g_socket_binding == NULL);
66 g_socket_binding = new SocketBinding(bound_socket); 70 g_socket_binding = new SocketBinding(bound_socket);
67 } 71 }
68 72
69 void WINAPI NaClStubThread(void *thread_arg) { 73 void WINAPI NaClStubThread(void *thread_arg) {
70 UNREFERENCED_PARAMETER(thread_arg); 74 UNREFERENCED_PARAMETER(thread_arg);
71 75
72 if (!NaClDebugBindSocket()) {
73 return;
74 }
75 while (1) { 76 while (1) {
76 // Wait for a connection. 77 // Wait for a connection.
77 nacl::scoped_ptr<ITransport> trans(g_socket_binding->AcceptConnection()); 78 nacl::scoped_ptr<ITransport> trans(g_socket_binding->AcceptConnection());
78 if (NULL == trans.get()) continue; 79 if (NULL == trans.get()) continue;
79 80
80 // Create a new session for this connection 81 // Create a new session for this connection
81 Session ses(trans.get()); 82 Session ses(trans.get());
82 ses.SetFlags(Session::DEBUG_MASK); 83 ses.SetFlags(Session::DEBUG_MASK);
83 84
84 NaClLog(LOG_WARNING, "nacl_debug(%d) : Connected, happy debugging!\n", 85 NaClLog(LOG_WARNING, "nacl_debug(%d) : Connected, happy debugging!\n",
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 NaClLog(LOG_ERROR, "NaClDebugInit: Failed to initialize fault handling\n"); 118 NaClLog(LOG_ERROR, "NaClDebugInit: Failed to initialize fault handling\n");
118 return 0; 119 return 0;
119 } 120 }
120 nap->debug_stub_callbacks = &debug_callbacks; 121 nap->debug_stub_callbacks = &debug_callbacks;
121 122
122 CHECK(g_target == NULL); 123 CHECK(g_target == NULL);
123 g_target = new Target(nap); 124 g_target = new Target(nap);
124 CHECK(g_target != NULL); 125 CHECK(g_target != NULL);
125 g_target->Init(); 126 g_target->Init();
126 127
128 if (!NaClDebugBindSocket()) {
129 return 0;
130 }
131 nap->debug_stub_port = g_socket_binding->GetBoundPort();
132
127 NaClThread *thread = new NaClThread; 133 NaClThread *thread = new NaClThread;
128 CHECK(thread != NULL); 134 CHECK(thread != NULL);
129 135
130 NaClLog(LOG_WARNING, "nacl_debug(%d) : Debugging started.\n", __LINE__); 136 NaClLog(LOG_WARNING, "nacl_debug(%d) : Debugging started.\n", __LINE__);
131 CHECK(NaClThreadCtor(thread, NaClStubThread, NULL, NACL_KERN_STACK_SIZE)); 137 CHECK(NaClThreadCtor(thread, NaClStubThread, NULL, NACL_KERN_STACK_SIZE));
132 138
133 return 1; 139 return 1;
134 } 140 }
OLDNEW
« no previous file with comments | « src/public/chrome_main.h ('k') | src/trusted/debug_stub/transport.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698