@@ -35,7 +35,7 @@ bool await_response(std::string message, SOCKET socket)
35
35
return !starts_with (answer, kGDBErrorPrefix );
36
36
}
37
37
38
- bool init (std::string& executable, SOCKET socket, std::string& application_identifier, std::map<std::string, ApplicationCache>& apps_cache)
38
+ bool init (std::string& executable, SOCKET socket, std::string& application_identifier, std::map<std::string, ApplicationCache>& apps_cache, bool wait_for_debugger = false )
39
39
{
40
40
if (apps_cache[application_identifier].has_initialized_gdb )
41
41
return true ;
@@ -50,21 +50,25 @@ bool init(std::string& executable, SOCKET socket, std::string& application_ident
50
50
// We need this because GDB isn't connected to any inferior process (e.g. the application we want to control)
51
51
RETURN_IF_FALSE (await_response (" QSetDisableASLR:1" , socket));
52
52
std::stringstream result;
53
+ std::string debugBrk = " --nativescript-debug-brk" ;
53
54
// Initializes the argv in the form of arglen,argnum,arg
54
55
// In our case:
55
56
// arglen - twice the size of the original argument because we HEX encode it and every symbol becomes two bytes
56
57
// argnum - 0 we only have one arg
57
58
// arg - the actual arg, which is HEX encoded because we set the environment that way
58
59
result << " A" << executable.size () * 2 << " ,0," << to_hex (executable);
60
+ if (wait_for_debugger) {
61
+ result << debugBrk.size () * 2 << " ,1," << to_hex (debugBrk);
62
+ }
59
63
RETURN_IF_FALSE (await_response (result.str (), socket));
60
64
// After all of this is done we can actually call a method with these arguments
61
65
apps_cache[application_identifier].has_initialized_gdb = true ;
62
66
return true ;
63
67
}
64
68
65
- bool run_application (std::string& executable, SOCKET socket, std::string& application_identifier, DeviceData* device_data)
69
+ bool run_application (std::string& executable, SOCKET socket, std::string& application_identifier, DeviceData* device_data, bool wait_for_debugger )
66
70
{
67
- RETURN_IF_FALSE (init (executable, socket, application_identifier, device_data->apps_cache ));
71
+ RETURN_IF_FALSE (init (executable, socket, application_identifier, device_data->apps_cache , wait_for_debugger ));
68
72
// Couldn't find official info on this but I'm guessing this is the method we need to call
69
73
RETURN_IF_FALSE (await_response (" qLaunchSuccess" , socket));
70
74
// vCont specifies a command to be run - c means continue
@@ -81,9 +85,9 @@ bool run_application(std::string& executable, SOCKET socket, std::string& applic
81
85
// We have decided we do not need this at the moment, but it is vital that it be read from the pipe
82
86
// Else it will remain there and may be read later on and mistaken for a response to same other package
83
87
std::string answer = receive_message_raw (socket);
84
-
88
+
85
89
detach_connection (socket, application_identifier, device_data);
86
-
90
+
87
91
return true ;
88
92
}
89
93
@@ -106,7 +110,7 @@ bool stop_application(std::string & executable, SOCKET socket, std::string& appl
106
110
// If we get infromation about the thread then apparently it is now safe to send the kill command
107
111
// Thread information contains data that I cannot decipher - looks like this:
108
112
// $T11thread:42202;00:0540001000000000;01:0608000700000000;02:0000000000000000;03:000c000000000000;04:0321000000000000;05:ffffffff00000000;06:0000000000000000;07:0100000000000000;08:bffbffff00000000;09:0000000700000000;0a:0001000700000000;0b:c0bdf0ff00000000;0c:034e0d00004d0d00;0d:0000000000000000;0e:004e0d00004e0d00;0f:0000000000000000;10:e1ffffffffffffff;11:20a59e8201000000;12:0000000000000000;13:0000000000000000;14:ffffffff00000000;15:0321000000000000;16:000c000000000000;17:08a0d66f01000000;18:0608000700000000;19:0000000000000000;1a:0608000700000000;1b:000c000000000000;1c:0100000000000000;1d:009fd66f01000000;1e:dcffab8101000000;1f:b09ed66f01000000;20:6c01ac8101000000;21:00000060;metype:5;mecount:2;medata:10003;medata:11;memory:0x16fd69f00=609fd66f01000000ecdcab8201000000;memory:0x16fd69f60=70acd66f0100000008b9ab8201000000;#00
109
- // If the application is not running the gdb will return $OK#00 instead of the above message.
113
+ // If the application is not running the gdb will return $OK#00 instead of the above message.
110
114
if (contains (answer, " thread" ) || contains (answer, " $OK#" ))
111
115
{
112
116
can_send_kill = true ;
@@ -134,7 +138,7 @@ void detach_connection(SOCKET socket, std::string& application_identifier, Devic
134
138
device_data->apps_cache [application_identifier].has_initialized_gdb = false ;
135
139
device_data->services .erase (kDebugServer );
136
140
#ifdef _WIN32
137
- closesocket (socket);
141
+ closesocket (socket);
138
142
#else
139
143
close (socket);
140
144
#endif
0 commit comments