Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 (g_socket_binding == NULL) { | 52 if (g_socket_binding == NULL) { |
| 53 NaClLog(LOG_ERROR, "NaClStubThread: Failed to bind TCP port '%s'\n", | 53 g_socket_binding = SocketBinding::Bind("127.0.0.1:0"); |
| 54 addr); | 54 } |
| 55 // If port 4014 is not available, try any port. | |
|
Mark Seaborn
2014/03/26 23:17:35
This comment belongs before the previous if().
bradn
2014/04/01 18:31:20
Done.
| |
| 56 if (g_socket_binding == NULL) { | |
| 57 NaClLog(LOG_ERROR, | |
| 58 "NaClDebugStubBindSocke: Failed to bind any TCP port\n"); | |
|
Mark Seaborn
2014/03/26 23:17:35
"NaClDebugBindSocket". No "Stub", missing "t".
bradn
2014/04/01 18:31:20
Done.
| |
| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
| 127 NaClThread *thread = new NaClThread; | 128 NaClThread *thread = new NaClThread; |
| 128 CHECK(thread != NULL); | 129 CHECK(thread != NULL); |
| 129 | 130 |
| 131 if (!NaClDebugBindSocket()) { | |
|
Mark Seaborn
2014/03/26 23:17:35
This belongs before "new NaClThread". "new NaClTh
bradn
2014/04/01 18:31:20
Done.
| |
| 132 NaClLog(LOG_ERROR, "NaClDebugInit: Failed to bind debug socket\n"); | |
|
Mark Seaborn
2014/03/26 23:17:35
NaClDebugBindSocket() already prints an error, so
bradn
2014/04/01 18:31:20
Done.
| |
| 133 return 0; | |
| 134 } | |
| 135 nap->debug_stub_port = g_socket_binding->GetBoundPort(); | |
| 136 | |
| 130 NaClLog(LOG_WARNING, "nacl_debug(%d) : Debugging started.\n", __LINE__); | 137 NaClLog(LOG_WARNING, "nacl_debug(%d) : Debugging started.\n", __LINE__); |
| 131 CHECK(NaClThreadCtor(thread, NaClStubThread, NULL, NACL_KERN_STACK_SIZE)); | 138 CHECK(NaClThreadCtor(thread, NaClStubThread, NULL, NACL_KERN_STACK_SIZE)); |
| 132 | 139 |
| 133 return 1; | 140 return 1; |
| 134 } | 141 } |
| OLD | NEW |