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

Unified 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: Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: src/trusted/debug_stub/nacl_debug.cc
diff --git a/src/trusted/debug_stub/nacl_debug.cc b/src/trusted/debug_stub/nacl_debug.cc
index 057d4bb6b622193a8f63aa0a82a341e817efbbd3..24073b3127ed680470a704df8f667a64b7abab31 100644
--- a/src/trusted/debug_stub/nacl_debug.cc
+++ b/src/trusted/debug_stub/nacl_debug.cc
@@ -47,16 +47,20 @@ static SocketBinding *g_socket_binding = NULL;
int NaClDebugBindSocket() {
if (g_socket_binding == NULL) {
NaClDebugStubInit();
- const char *addr = "127.0.0.1:4014";
- g_socket_binding = SocketBinding::Bind(addr);
+ // Try port 4014 first for compatibility.
+ g_socket_binding = SocketBinding::Bind("127.0.0.1:4014");
if (g_socket_binding == NULL) {
- NaClLog(LOG_ERROR, "NaClStubThread: Failed to bind TCP port '%s'\n",
- addr);
+ g_socket_binding = SocketBinding::Bind("127.0.0.1:0");
+ }
+ // 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.
+ if (g_socket_binding == NULL) {
+ NaClLog(LOG_ERROR,
+ "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.
return 0;
}
NaClLog(LOG_WARNING,
- "nacl_debug(%d) : Connect GDB with 'target remote %s'.\n",
- __LINE__, addr);
+ "nacl_debug(%d) : Connect GDB with 'target remote :%d\n",
+ __LINE__, g_socket_binding->GetBoundPort());
}
return 1;
}
@@ -69,9 +73,6 @@ void NaClDebugSetBoundSocket(NaClSocketHandle bound_socket) {
void WINAPI NaClStubThread(void *thread_arg) {
UNREFERENCED_PARAMETER(thread_arg);
- if (!NaClDebugBindSocket()) {
- return;
- }
while (1) {
// Wait for a connection.
nacl::scoped_ptr<ITransport> trans(g_socket_binding->AcceptConnection());
@@ -127,6 +128,12 @@ int NaClDebugInit(struct NaClApp *nap) {
NaClThread *thread = new NaClThread;
CHECK(thread != NULL);
+ 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.
+ 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.
+ return 0;
+ }
+ nap->debug_stub_port = g_socket_binding->GetBoundPort();
+
NaClLog(LOG_WARNING, "nacl_debug(%d) : Debugging started.\n", __LINE__);
CHECK(NaClThreadCtor(thread, NaClStubThread, NULL, NACL_KERN_STACK_SIZE));

Powered by Google App Engine
This is Rietveld 408576698