|
30 | 30 |
|
31 | 31 | #include <iomanip>
|
32 | 32 | #include <sstream>
|
33 |
| - |
34 | 33 | #include <TargetConditionals.h> // for endianness predefines
|
35 | 34 |
|
36 | 35 | //----------------------------------------------------------------------
|
@@ -155,9 +154,9 @@ RNBRemote::CreatePacketTable ()
|
155 | 154 | t.push_back (Packet (remove_read_watch_bp, &RNBRemote::HandlePacket_z, NULL, "z3", "Remove read watchpoint"));
|
156 | 155 | t.push_back (Packet (insert_access_watch_bp, &RNBRemote::HandlePacket_z, NULL, "Z4", "Insert access watchpoint"));
|
157 | 156 | t.push_back (Packet (remove_access_watch_bp, &RNBRemote::HandlePacket_z, NULL, "z4", "Remove access watchpoint"));
|
| 157 | + t.push_back (Packet (query_monitor, &RNBRemote::HandlePacket_qCmd, NULL, "qCmd", "Monitor command")); |
158 | 158 | t.push_back (Packet (query_current_thread_id, &RNBRemote::HandlePacket_qC, NULL, "qC", "Query current thread ID"));
|
159 | 159 | t.push_back (Packet (query_get_pid, &RNBRemote::HandlePacket_qGetPid, NULL, "qGetPid", "Query process id"));
|
160 |
| -// t.push_back (Packet (query_memory_crc, &RNBRemote::HandlePacket_UNIMPLEMENTED, NULL, "qCRC:", "Compute CRC of memory region")); |
161 | 160 | t.push_back (Packet (query_thread_ids_first, &RNBRemote::HandlePacket_qThreadInfo, NULL, "qfThreadInfo", "Get list of active threads (first req)"));
|
162 | 161 | t.push_back (Packet (query_thread_ids_subsequent, &RNBRemote::HandlePacket_qThreadInfo, NULL, "qsThreadInfo", "Get list of active threads (subsequent req)"));
|
163 | 162 | // APPLE LOCAL: qThreadStopInfo
|
@@ -1435,6 +1434,135 @@ RNBRemote::HandlePacket_qThreadExtraInfo (const char *p)
|
1435 | 1434 | return SendPacket ("");
|
1436 | 1435 | }
|
1437 | 1436 |
|
| 1437 | + |
| 1438 | +const char *k_space_delimiters = " \t"; |
| 1439 | +static void |
| 1440 | +skip_spaces (std::string &line) |
| 1441 | +{ |
| 1442 | + if (!line.empty()) |
| 1443 | + { |
| 1444 | + size_t space_pos = line.find_first_not_of (k_space_delimiters); |
| 1445 | + if (space_pos > 0) |
| 1446 | + line.erase(0, space_pos); |
| 1447 | + } |
| 1448 | +} |
| 1449 | + |
| 1450 | +static std::string |
| 1451 | +get_identifier (std::string &line) |
| 1452 | +{ |
| 1453 | + std::string word; |
| 1454 | + skip_spaces (line); |
| 1455 | + const size_t line_size = line.size(); |
| 1456 | + size_t end_pos; |
| 1457 | + for (end_pos = 0; end_pos < line_size; ++end_pos) |
| 1458 | + { |
| 1459 | + if (end_pos == 0) |
| 1460 | + { |
| 1461 | + if (isalpha(line[end_pos]) || line[end_pos] == '_') |
| 1462 | + continue; |
| 1463 | + } |
| 1464 | + else if (isalnum(line[end_pos]) || line[end_pos] == '_') |
| 1465 | + continue; |
| 1466 | + break; |
| 1467 | + } |
| 1468 | + word.assign (line, 0, end_pos); |
| 1469 | + line.erase(0, end_pos); |
| 1470 | + return word; |
| 1471 | +} |
| 1472 | + |
| 1473 | +static std::string |
| 1474 | +get_operator (std::string &line) |
| 1475 | +{ |
| 1476 | + std::string op; |
| 1477 | + skip_spaces (line); |
| 1478 | + if (!line.empty()) |
| 1479 | + { |
| 1480 | + if (line[0] == '=') |
| 1481 | + { |
| 1482 | + op = '='; |
| 1483 | + line.erase(0,1); |
| 1484 | + } |
| 1485 | + } |
| 1486 | + return op; |
| 1487 | +} |
| 1488 | + |
| 1489 | +static std::string |
| 1490 | +get_value (std::string &line) |
| 1491 | +{ |
| 1492 | + std::string value; |
| 1493 | + skip_spaces (line); |
| 1494 | + if (!line.empty()) |
| 1495 | + { |
| 1496 | + value.swap(line); |
| 1497 | + } |
| 1498 | + return value; |
| 1499 | +} |
| 1500 | + |
| 1501 | + |
| 1502 | +extern void FileLogCallback(void *baton, uint32_t flags, const char *format, va_list args); |
| 1503 | +extern void ASLLogCallback(void *baton, uint32_t flags, const char *format, va_list args); |
| 1504 | + |
| 1505 | +rnb_err_t |
| 1506 | +RNBRemote::HandlePacket_qCmd (const char *p) |
| 1507 | +{ |
| 1508 | + const char *c = p + strlen("qCmd,"); |
| 1509 | + std::string line; |
| 1510 | + while (c[0] && c[1]) |
| 1511 | + { |
| 1512 | + char smallbuf[3] = { c[0], c[1], '\0' }; |
| 1513 | + errno = 0; |
| 1514 | + int ch = strtoul (smallbuf, NULL, 16); |
| 1515 | + if (errno != 0 && ch == 0) |
| 1516 | + return HandlePacket_ILLFORMED (__FILE__, __LINE__, p, "non-hex char in payload of qCmd packet"); |
| 1517 | + line.push_back(ch); |
| 1518 | + c += 2; |
| 1519 | + } |
| 1520 | + if (*c == '\0') |
| 1521 | + { |
| 1522 | + std::string command = get_identifier(line); |
| 1523 | + if (command.compare("set") == 0) |
| 1524 | + { |
| 1525 | + std::string variable = get_identifier (line); |
| 1526 | + std::string op = get_operator (line); |
| 1527 | + std::string value = get_value (line); |
| 1528 | + if (variable.compare("logfile") == 0) |
| 1529 | + { |
| 1530 | + FILE *log_file = fopen(value.c_str(), "w"); |
| 1531 | + if (log_file) |
| 1532 | + { |
| 1533 | + DNBLogSetLogCallback(FileLogCallback, log_file); |
| 1534 | + return SendPacket ("OK"); |
| 1535 | + } |
| 1536 | + return SendPacket ("E71"); |
| 1537 | + } |
| 1538 | + else if (variable.compare("logmask") == 0) |
| 1539 | + { |
| 1540 | + char *end; |
| 1541 | + errno = 0; |
| 1542 | + uint32_t logmask = strtoul (value.c_str(), &end, 0); |
| 1543 | + if (errno == 0 && end && *end == '\0') |
| 1544 | + { |
| 1545 | + DNBLogSetLogMask (logmask); |
| 1546 | + if (!DNBLogGetLogCallback()) |
| 1547 | + DNBLogSetLogCallback(ASLLogCallback, NULL); |
| 1548 | + return SendPacket ("OK"); |
| 1549 | + } |
| 1550 | + errno = 0; |
| 1551 | + logmask = strtoul (value.c_str(), &end, 16); |
| 1552 | + if (errno == 0 && end && *end == '\0') |
| 1553 | + { |
| 1554 | + DNBLogSetLogMask (logmask); |
| 1555 | + return SendPacket ("OK"); |
| 1556 | + } |
| 1557 | + return SendPacket ("E72"); |
| 1558 | + } |
| 1559 | + return SendPacket ("E70"); |
| 1560 | + } |
| 1561 | + return SendPacket ("E69"); |
| 1562 | + } |
| 1563 | + return SendPacket ("E73"); |
| 1564 | +} |
| 1565 | + |
1438 | 1566 | rnb_err_t
|
1439 | 1567 | RNBRemote::HandlePacket_qC (const char *p)
|
1440 | 1568 | {
|
|
0 commit comments