Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* ********************************************************** | 1 /* ********************************************************** |
2 * Copyright (c) 2010-2014 Google, Inc. All rights reserved. | 2 * Copyright (c) 2010-2014 Google, Inc. All rights reserved. |
3 * Copyright (c) 2010 VMware, Inc. All rights reserved. | 3 * Copyright (c) 2010 VMware, Inc. All rights reserved. |
4 * **********************************************************/ | 4 * **********************************************************/ |
5 | 5 |
6 /* Dr. Memory: the memory debugger | 6 /* Dr. Memory: the memory debugger |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Lesser General Public | 9 * modify it under the terms of the GNU Lesser General Public |
10 * License as published by the Free Software Foundation; | 10 * License as published by the Free Software Foundation; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 if (uname(&uinfo) != 0) | 180 if (uname(&uinfo) != 0) |
181 return false; | 181 return false; |
182 # define MIN_DARWIN_VERSION_SUPPORTED 11 /* OSX 10.7.x */ | 182 # define MIN_DARWIN_VERSION_SUPPORTED 11 /* OSX 10.7.x */ |
183 # define MAX_DARWIN_VERSION_SUPPORTED 13 /* OSX 10.9.x */ | 183 # define MAX_DARWIN_VERSION_SUPPORTED 13 /* OSX 10.9.x */ |
184 return (dr_sscanf(uinfo.release, "%d", &kernel_major) == 1 && | 184 return (dr_sscanf(uinfo.release, "%d", &kernel_major) == 1 && |
185 kernel_major <= MAX_DARWIN_VERSION_SUPPORTED && | 185 kernel_major <= MAX_DARWIN_VERSION_SUPPORTED && |
186 kernel_major >= MIN_DARWIN_VERSION_SUPPORTED); | 186 kernel_major >= MIN_DARWIN_VERSION_SUPPORTED); |
187 } | 187 } |
188 #endif /* WINDOWS */ | 188 #endif /* WINDOWS */ |
189 | 189 |
190 static const char * | |
191 dr_config_status_to_msg(dr_config_status_t status) | |
bruening
2014/08/06 23:19:46
Do you think drconfiglib should provide this routi
zhaoqin
2014/08/08 19:18:03
hmm, actually, I should add it to drconfiglib now.
| |
192 { | |
193 const char *msg; | |
194 switch (status) { | |
195 case DR_SUCCESS: | |
196 /* Operation succeeded. */ | |
197 msg = "successful"; | |
198 break; | |
199 case DR_PROC_REG_EXISTS: | |
200 /* Process registration failed due to an existing registration. */ | |
201 msg = "registration already exists"; | |
202 break; | |
203 case DR_PROC_REG_INVALID: | |
204 /* Operation failed because the supplied process is not registered. */ | |
205 msg = "target process is not registerred"; | |
bruening
2014/08/06 23:19:46
spelling
zhaoqin
2014/08/08 19:18:03
Done.
| |
206 break; | |
207 case DR_PRIORITY_INVALID: | |
208 /* Client registration failed due to an invalid priority value. */ | |
209 msg = "invalid priority value"; | |
210 break; | |
211 case DR_ID_CONFLICTING: | |
212 /* Client registration failed due to a conflicting ID. */ | |
213 msg = "conflict id"; | |
bruening
2014/08/06 23:19:46
s/conflict/conflicting/
zhaoqin
2014/08/08 19:18:03
Done.
| |
214 break; | |
215 case DR_ID_INVALID: | |
216 /* Client operation failed due to an invalid client ID. */ | |
217 msg = "invalid client ID"; | |
218 break; | |
219 case DR_NUDGE_PID_NOT_INJECTED: | |
220 /* Nudge operation failed because the specified process id is not under DR. */ | |
221 msg = "target process is not under Dr.Memory"; | |
bruening
2014/08/06 23:19:46
s/Dr.M/Dr. M/
zhaoqin
2014/08/08 19:18:04
replace it with DynamoRIO since moving it to Dynam
| |
222 break; | |
223 case DR_NUDGE_TIMEOUT: | |
224 /* Nudge operation timed out waiting for target process to finish handli ng a nudge.*/ | |
bruening
2014/08/06 23:19:46
style
bruening
2014/08/06 23:19:46
(IMHO these comments could all be removed from her
zhaoqin
2014/08/08 19:18:03
Done.
zhaoqin
2014/08/08 19:18:03
Done.
| |
225 msg = "timed out"; | |
226 break; | |
227 case DR_CONFIG_STRING_TOO_LONG: | |
228 /* Field length exceeded, probably due to a too-long option string */ | |
229 msg = "config option string too long"; | |
230 break; | |
231 case DR_CONFIG_FILE_WRITE_FAILED: | |
232 /* Failed to write to the config file. */ | |
233 msg = "failed to write to the config file"; | |
bruening
2014/08/06 23:19:46
Perhaps this should also say "check permissions on
zhaoqin
2014/08/08 19:18:04
For moving to DynamoRIO, I think we can only say "
| |
234 break; | |
235 case DR_NUDGE_PID_NOT_FOUND: | |
236 /* Nudge operation failed because the specified process id does not exis t. */ | |
237 msg = "target process id does not exist"; | |
238 break; | |
239 case DR_FAILURE: | |
240 default: | |
241 msg = "unknown failure, check caller permissions for this operation"; | |
bruening
2014/08/06 23:19:46
"caller"? Does the user know anything about "call
zhaoqin
2014/08/08 19:18:03
just keep unknown error.
| |
242 break; | |
243 } | |
244 return msg; | |
245 } | |
246 | |
190 static const char *prefix = PREFIX_DEFAULT_MAIN_THREAD; | 247 static const char *prefix = PREFIX_DEFAULT_MAIN_THREAD; |
191 | 248 |
192 static void | 249 static void |
193 pause_if_in_cmd(void) | 250 pause_if_in_cmd(void) |
194 { | 251 { |
195 #ifdef WINDOWS | 252 #ifdef WINDOWS |
196 if (!batch && | 253 if (!batch && |
197 (dr_using_console() || | 254 (dr_using_console() || |
198 /* i#1157: on win8 dr_using_console() always returns false, so we | 255 /* i#1157: on win8 dr_using_console() always returns false, so we |
199 * always pause unless -batch | 256 * always pause unless -batch |
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
937 bool exit0 = false; | 994 bool exit0 = false; |
938 bool dr_logdir_specified = false; | 995 bool dr_logdir_specified = false; |
939 bool doubledash_present = false; | 996 bool doubledash_present = false; |
940 | 997 |
941 #ifdef WINDOWS | 998 #ifdef WINDOWS |
942 time_t start_time, end_time; | 999 time_t start_time, end_time; |
943 #endif | 1000 #endif |
944 | 1001 |
945 drfront_status_t sc; | 1002 drfront_status_t sc; |
946 bool res; | 1003 bool res; |
1004 dr_config_status_t status; | |
947 | 1005 |
948 if (dr_standalone_init() == NULL) { | 1006 if (dr_standalone_init() == NULL) { |
949 /* We assume this is due to a new version of Windows */ | 1007 /* We assume this is due to a new version of Windows */ |
950 fatal("this version of Windows is not supported by Dr. Memory."); | 1008 fatal("this version of Windows is not supported by Dr. Memory."); |
951 } | 1009 } |
952 | 1010 |
953 #ifdef WINDOWS | 1011 #ifdef WINDOWS |
954 /* i#1377: we can't trust GetVersionEx() b/c it pretends 6.3 (Win8.1) is | 1012 /* i#1377: we can't trust GetVersionEx() b/c it pretends 6.3 (Win8.1) is |
955 * 6.2 (Win8)! Thus we use DR's version. | 1013 * 6.2 (Win8)! Thus we use DR's version. |
956 */ | 1014 */ |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1285 BUFPRINT(client_ops, BUFFER_SIZE_ELEMENTS(client_ops), | 1343 BUFPRINT(client_ops, BUFFER_SIZE_ELEMENTS(client_ops), |
1286 cliops_sofar, len, "`%s` ", argv[i]); | 1344 cliops_sofar, len, "`%s` ", argv[i]); |
1287 } | 1345 } |
1288 } | 1346 } |
1289 | 1347 |
1290 #ifndef MACOS /* XXX i#1286: implement nudge on MacOS */ | 1348 #ifndef MACOS /* XXX i#1286: implement nudge on MacOS */ |
1291 if (nudge_pid != 0) { | 1349 if (nudge_pid != 0) { |
1292 if (i < argc) | 1350 if (i < argc) |
1293 usage("%s", "-nudge does not take an app to run"); | 1351 usage("%s", "-nudge does not take an app to run"); |
1294 /* could also complain about other client or app specific ops */ | 1352 /* could also complain about other client or app specific ops */ |
1295 res = dr_nudge_pid(nudge_pid, DRMEM_CLIENT_ID, NUDGE_LEAK_SCAN, INFINITE ); | 1353 res = dr_nudge_pid(nudge_pid, DRMEM_CLIENT_ID, NUDGE_LEAK_SCAN, INFINITE ); |
bruening
2014/08/06 23:19:46
Is this a bug b/c "res" is the wrong type?
zhaoqin
2014/08/08 19:18:04
good catch.
| |
1296 if (res != DR_SUCCESS) { | 1354 if (res != DR_SUCCESS) { |
1297 fatal("error nudging %d%s", nudge_pid, | 1355 const char *err_msg = dr_config_status_to_msg(res); |
1298 (res == DR_NUDGE_PID_NOT_INJECTED) ? ": no such Dr. Memory pro cess" | 1356 fatal("error nudging %d, error code %d (%s)", nudge_pid, res, err_ms g); |
1299 : ""); | |
1300 assert(false); /* shouldn't get here */ | 1357 assert(false); /* shouldn't get here */ |
1301 } | 1358 } |
1302 exit(0); | 1359 exit(0); |
1303 } | 1360 } |
1304 #endif | 1361 #endif |
1305 | 1362 |
1306 if (i >= argc) | 1363 if (i >= argc) |
1307 usage("%s", "no app specified"); | 1364 usage("%s", "no app specified"); |
1308 app_name = argv[i]; | 1365 app_name = argv[i]; |
1309 get_full_path(app_name, full_app_name, BUFFER_SIZE_ELEMENTS(full_app_name)); | 1366 get_full_path(app_name, full_app_name, BUFFER_SIZE_ELEMENTS(full_app_name)); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1517 | 1574 |
1518 /* we need to locate the results file, but only for top-level process (i#328 ) */ | 1575 /* we need to locate the results file, but only for top-level process (i#328 ) */ |
1519 BUFPRINT(client_ops, BUFFER_SIZE_ELEMENTS(client_ops), | 1576 BUFPRINT(client_ops, BUFFER_SIZE_ELEMENTS(client_ops), |
1520 cliops_sofar, len, "-resfile %d ", pid); | 1577 cliops_sofar, len, "-resfile %d ", pid); |
1521 | 1578 |
1522 process = dr_inject_get_image_name(inject_data); | 1579 process = dr_inject_get_image_name(inject_data); |
1523 /* we don't care if this app is already registered for DR b/c our | 1580 /* we don't care if this app is already registered for DR b/c our |
1524 * this-pid config will override | 1581 * this-pid config will override |
1525 */ | 1582 */ |
1526 info("configuring %s pid=%d dr_ops=\"%s\"", process, pid, dr_ops); | 1583 info("configuring %s pid=%d dr_ops=\"%s\"", process, pid, dr_ops); |
1527 if (dr_register_process(process, pid, | 1584 status = dr_register_process(process, pid, |
1528 false/*local*/, dr_root, DR_MODE_CODE_MANIPULATION, | 1585 false/*local*/, dr_root, DR_MODE_CODE_MANIPULA TION, |
1529 use_dr_debug, DR_PLATFORM_DEFAULT, dr_ops) != DR_SUC CESS) { | 1586 use_dr_debug, DR_PLATFORM_DEFAULT, dr_ops); |
1530 fatal("failed to register DynamoRIO configuration"); | 1587 if (status != DR_SUCCESS) { |
1588 const char *err_msg = dr_config_status_to_msg(status); | |
1589 fatal("%d (%s)\nFailed to register DynamoRIO configuration for \"%s\"(%d ) " | |
bruening
2014/08/06 23:19:46
Hmm, so this will read sthg like "ERROR: 3 (failed
zhaoqin
2014/08/08 19:18:03
ok, I used to put the error at the end, but the li
| |
1590 "dr_ops=\"%s\"", | |
1591 status, err_msg, process, pid, dr_ops); | |
1531 goto error; /* actually won't get here */ | 1592 goto error; /* actually won't get here */ |
1532 } | 1593 } |
1533 info("configuring client \"%s\" ops=\"%s\"", client_path, client_ops); | 1594 info("configuring client \"%s\" ops=\"%s\"", client_path, client_ops); |
1534 if (dr_register_client(process, pid, | 1595 status = dr_register_client(process, pid, |
1535 false/*local*/, DR_PLATFORM_DEFAULT, DRMEM_CLIENT_ID, | 1596 false/*local*/, DR_PLATFORM_DEFAULT, DRMEM_CLIEN T_ID, |
1536 0, client_path, client_ops) != DR_SUCCESS) { | 1597 0, client_path, client_ops); |
1537 fatal("failed to register DynamoRIO client configuration"); | 1598 if (status != DR_SUCCESS) { |
1599 const char *err_msg = dr_config_status_to_msg(status); | |
1600 fatal("%d (%s)\nFailed to register DynamoRIO client configuration for \" %s\", " | |
1601 "ops=\"%s\"", status, err_msg, client_path, client_ops); | |
bruening
2014/08/06 23:19:46
Ditto
zhaoqin
2014/08/08 19:18:03
Done.
| |
1538 goto error; /* actually won't get here */ | 1602 goto error; /* actually won't get here */ |
1539 } | 1603 } |
1540 | 1604 |
1541 if (native_parent) { | 1605 if (native_parent) { |
1542 /* Create a regular config file without -native_parent so the children w ill | 1606 /* Create a regular config file without -native_parent so the children w ill |
1543 * run normally. | 1607 * run normally. |
1544 */ | 1608 */ |
1545 info("configuring child processes"); | 1609 info("configuring child processes"); |
1546 if (dr_process_is_registered(process, 0, false/*local*/, DR_PLATFORM_DEF AULT, | 1610 if (dr_process_is_registered(process, 0, false/*local*/, DR_PLATFORM_DEF AULT, |
1547 NULL, NULL, NULL, NULL)) { | 1611 NULL, NULL, NULL, NULL)) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1612 if (sc != DRFRONT_SUCCESS) | 1676 if (sc != DRFRONT_SUCCESS) |
1613 fatal("failed to free memory for args: %d", sc); | 1677 fatal("failed to free memory for args: %d", sc); |
1614 if (errcode != 0) { | 1678 if (errcode != 0) { |
1615 /* We use a prefix to integrate better with tool output, esp inside | 1679 /* We use a prefix to integrate better with tool output, esp inside |
1616 * the VS IDE as an External Tool. | 1680 * the VS IDE as an External Tool. |
1617 */ | 1681 */ |
1618 warn_prefix("application exited with abnormal code 0x%x", errcode); | 1682 warn_prefix("application exited with abnormal code 0x%x", errcode); |
1619 } | 1683 } |
1620 return (exit0 ? 0 : errcode); | 1684 return (exit0 ? 0 : errcode); |
1621 } | 1685 } |
OLD | NEW |