Commit 073abfce authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

- translated sprintf calls into snprintf

- added helper for sending strings in hex form
parent 8e0dcc41
...@@ -791,7 +791,7 @@ static void get_process_info(struct gdb_context* gdbctx, char* buffer, size_t le ...@@ -791,7 +791,7 @@ static void get_process_info(struct gdb_context* gdbctx, char* buffer, size_t le
strcpy(buffer, "Running"); strcpy(buffer, "Running");
} }
else else
sprintf(buffer, "Terminated (%lu)", status); snprintf(buffer, len, "Terminated (%lu)", status);
switch (GetPriorityClass(gdbctx->process->handle)) switch (GetPriorityClass(gdbctx->process->handle))
{ {
...@@ -833,12 +833,12 @@ static void get_thread_info(struct gdb_context* gdbctx, unsigned tid, ...@@ -833,12 +833,12 @@ static void get_thread_info(struct gdb_context* gdbctx, unsigned tid,
{ {
case -1: break; case -1: break;
case 0: strcpy(buffer, "Running"); break; case 0: strcpy(buffer, "Running"); break;
default: sprintf(buffer, "Suspended (%lu)", status - 1); default: snprintf(buffer, len, "Suspended (%lu)", status - 1);
} }
ResumeThread(thd->handle); ResumeThread(thd->handle);
} }
else else
sprintf(buffer, "Terminated (exit code = %lu)", status); snprintf(buffer, len, "Terminated (exit code = %lu)", status);
} }
else else
{ {
...@@ -854,7 +854,7 @@ static void get_thread_info(struct gdb_context* gdbctx, unsigned tid, ...@@ -854,7 +854,7 @@ static void get_thread_info(struct gdb_context* gdbctx, unsigned tid,
case THREAD_PRIORITY_IDLE: strcat(buffer, ", priority idle"); break; case THREAD_PRIORITY_IDLE: strcat(buffer, ", priority idle"); break;
case THREAD_PRIORITY_NORMAL: strcat(buffer, ", priority normal"); break; case THREAD_PRIORITY_NORMAL: strcat(buffer, ", priority normal"); break;
case THREAD_PRIORITY_TIME_CRITICAL: strcat(buffer, ", priority time-critical"); break; case THREAD_PRIORITY_TIME_CRITICAL: strcat(buffer, ", priority time-critical"); break;
default: sprintf(buffer + strlen(buffer), ", priority = %d", prio); default: snprintf(buffer + strlen(buffer), len - strlen(buffer), ", priority = %d", prio);
} }
assert(strlen(buffer) < len); assert(strlen(buffer) < len);
} }
...@@ -883,6 +883,11 @@ static void packet_reply_hex_to(struct gdb_context* gdbctx, const void* src, int ...@@ -883,6 +883,11 @@ static void packet_reply_hex_to(struct gdb_context* gdbctx, const void* src, int
gdbctx->out_len += len * 2; gdbctx->out_len += len * 2;
} }
static inline void packet_reply_hex_to_str(struct gdb_context* gdbctx, const char* src)
{
packet_reply_hex_to(gdbctx, src, strlen(src));
}
static void packet_reply_val(struct gdb_context* gdbctx, unsigned long val, int len) static void packet_reply_val(struct gdb_context* gdbctx, unsigned long val, int len)
{ {
int i, shift; int i, shift;
...@@ -1281,11 +1286,12 @@ static void packet_query_monitor_wnd_helper(struct gdb_context* gdbctx, HWND hWn ...@@ -1281,11 +1286,12 @@ static void packet_query_monitor_wnd_helper(struct gdb_context* gdbctx, HWND hWn
packet_reply_open(gdbctx); packet_reply_open(gdbctx);
packet_reply_catc(gdbctx, 'O'); packet_reply_catc(gdbctx, 'O');
sprintf(buffer, "%*s%04x%*s%-17.17s %08lx %08lx %.14s\n", snprintf(buffer, sizeof(buffer),
indent, "", (UINT)hWnd, 13 - indent, "", "%*s%04x%*s%-17.17s %08lx %08lx %.14s\n",
clsName, GetWindowLong(hWnd, GWL_STYLE), indent, "", (UINT)hWnd, 13 - indent, "",
GetWindowLong(hWnd, GWL_WNDPROC), wndName); clsName, GetWindowLong(hWnd, GWL_STYLE),
packet_reply_hex_to(gdbctx, buffer, strlen(buffer)); GetWindowLong(hWnd, GWL_WNDPROC), wndName);
packet_reply_hex_to_str(gdbctx, buffer);
packet_reply_close(gdbctx); packet_reply_close(gdbctx);
if ((child = GetWindow(hWnd, GW_CHILD)) != 0) if ((child = GetWindow(hWnd, GW_CHILD)) != 0)
...@@ -1301,9 +1307,10 @@ static void packet_query_monitor_wnd(struct gdb_context* gdbctx, int len, const ...@@ -1301,9 +1307,10 @@ static void packet_query_monitor_wnd(struct gdb_context* gdbctx, int len, const
* marking the end of the output */ * marking the end of the output */
packet_reply_open(gdbctx); packet_reply_open(gdbctx);
packet_reply_catc(gdbctx, 'O'); packet_reply_catc(gdbctx, 'O');
sprintf(buffer, "%-16.16s %-17.17s %-8.8s %s\n", snprintf(buffer, sizeof(buffer),
"hwnd", "Class Name", " Style", " WndProc Text"); "%-16.16s %-17.17s %-8.8s %s\n",
packet_reply_hex_to(gdbctx, buffer, strlen(buffer)); "hwnd", "Class Name", " Style", " WndProc Text");
packet_reply_hex_to_str(gdbctx, buffer);
packet_reply_close(gdbctx); packet_reply_close(gdbctx);
/* FIXME: could also add a pmt to this command in str... */ /* FIXME: could also add a pmt to this command in str... */
...@@ -1330,9 +1337,10 @@ static void packet_query_monitor_process(struct gdb_context* gdbctx, int len, co ...@@ -1330,9 +1337,10 @@ static void packet_query_monitor_process(struct gdb_context* gdbctx, int len, co
packet_reply_open(gdbctx); packet_reply_open(gdbctx);
packet_reply_catc(gdbctx, 'O'); packet_reply_catc(gdbctx, 'O');
sprintf(buffer, " %-8.8s %-8.8s %-8.8s %s\n", snprintf(buffer, sizeof(buffer),
"pid", "threads", "parent", "executable" ); " %-8.8s %-8.8s %-8.8s %s\n",
packet_reply_hex_to(gdbctx, buffer, strlen(buffer)); "pid", "threads", "parent", "executable" );
packet_reply_hex_to_str(gdbctx, buffer);
packet_reply_close(gdbctx); packet_reply_close(gdbctx);
while (ok) while (ok)
...@@ -1341,10 +1349,11 @@ static void packet_query_monitor_process(struct gdb_context* gdbctx, int len, co ...@@ -1341,10 +1349,11 @@ static void packet_query_monitor_process(struct gdb_context* gdbctx, int len, co
if (entry.th32ProcessID == gdbctx->process->pid) deco = '>'; if (entry.th32ProcessID == gdbctx->process->pid) deco = '>';
packet_reply_open(gdbctx); packet_reply_open(gdbctx);
packet_reply_catc(gdbctx, 'O'); packet_reply_catc(gdbctx, 'O');
sprintf(buffer, "%c%08lx %-8ld %08lx '%s'\n", snprintf(buffer, sizeof(buffer),
deco, entry.th32ProcessID, entry.cntThreads, "%c%08lx %-8ld %08lx '%s'\n",
entry.th32ParentProcessID, entry.szExeFile); deco, entry.th32ProcessID, entry.cntThreads,
packet_reply_hex_to(gdbctx, buffer, strlen(buffer)); entry.th32ParentProcessID, entry.szExeFile);
packet_reply_hex_to_str(gdbctx, buffer);
packet_reply_close(gdbctx); packet_reply_close(gdbctx);
ok = Process32Next(snap, &entry); ok = Process32Next(snap, &entry);
} }
...@@ -1365,8 +1374,7 @@ static void packet_query_monitor_mem(struct gdb_context* gdbctx, int len, const ...@@ -1365,8 +1374,7 @@ static void packet_query_monitor_mem(struct gdb_context* gdbctx, int len, const
* marking the end of the output */ * marking the end of the output */
packet_reply_open(gdbctx); packet_reply_open(gdbctx);
packet_reply_catc(gdbctx, 'O'); packet_reply_catc(gdbctx, 'O');
sprintf(buffer, "Address Size State Type RWX\n"); packet_reply_hex_to_str(gdbctx, "Address Size State Type RWX\n");
packet_reply_hex_to(gdbctx, buffer, strlen(buffer));
packet_reply_close(gdbctx); packet_reply_close(gdbctx);
while (VirtualQueryEx(gdbctx->process->handle, addr, &mbi, sizeof(mbi)) >= sizeof(mbi)) while (VirtualQueryEx(gdbctx->process->handle, addr, &mbi, sizeof(mbi)) >= sizeof(mbi))
...@@ -1405,10 +1413,11 @@ static void packet_query_monitor_mem(struct gdb_context* gdbctx, int len, const ...@@ -1405,10 +1413,11 @@ static void packet_query_monitor_mem(struct gdb_context* gdbctx, int len, const
prot[0] = '\0'; prot[0] = '\0';
} }
packet_reply_open(gdbctx); packet_reply_open(gdbctx);
sprintf(buffer, "%08lx %08lx %s %s %s\n", snprintf(buffer, sizeof(buffer),
(DWORD)addr, mbi.RegionSize, state, type, prot); "%08lx %08lx %s %s %s\n",
(DWORD)addr, mbi.RegionSize, state, type, prot);
packet_reply_catc(gdbctx, 'O'); packet_reply_catc(gdbctx, 'O');
packet_reply_hex_to(gdbctx, buffer, strlen(buffer)); packet_reply_hex_to_str(gdbctx, buffer);
packet_reply_close(gdbctx); packet_reply_close(gdbctx);
if (addr + mbi.RegionSize < addr) /* wrap around ? */ if (addr + mbi.RegionSize < addr) /* wrap around ? */
...@@ -1425,12 +1434,12 @@ static void packet_query_monitor_trace(struct gdb_context* gdbctx, ...@@ -1425,12 +1434,12 @@ static void packet_query_monitor_trace(struct gdb_context* gdbctx,
if (len == 0) if (len == 0)
{ {
sprintf(buffer, "trace=%x\n", gdbctx->trace); snprintf(buffer, sizeof(buffer), "trace=%x\n", gdbctx->trace);
} }
else if (len >= 2 && str[0] == '=') else if (len >= 2 && str[0] == '=')
{ {
unsigned val = atoi(&str[1]); unsigned val = atoi(&str[1]);
sprintf(buffer, "trace: %x => %x\n", gdbctx->trace, val); snprintf(buffer, sizeof(buffer), "trace: %x => %x\n", gdbctx->trace, val);
gdbctx->trace = val; gdbctx->trace = val;
} }
else else
...@@ -1440,7 +1449,7 @@ static void packet_query_monitor_trace(struct gdb_context* gdbctx, ...@@ -1440,7 +1449,7 @@ static void packet_query_monitor_trace(struct gdb_context* gdbctx,
return; return;
} }
packet_reply_open(gdbctx); packet_reply_open(gdbctx);
packet_reply_hex_to(gdbctx, buffer, strlen(buffer)); packet_reply_hex_to_str(gdbctx, buffer);
packet_reply_close(gdbctx); packet_reply_close(gdbctx);
} }
...@@ -1474,9 +1483,9 @@ static void packet_query_monitor_linear(struct gdb_context* gdbctx, ...@@ -1474,9 +1483,9 @@ static void packet_query_monitor_linear(struct gdb_context* gdbctx,
le.BaseLow + ofs; le.BaseLow + ofs;
/* error */ /* error */
else linear = 0; else linear = 0;
sprintf(buffer, "0x%x", linear); snprintf(buffer, sizeof(buffer), "0x%x", linear);
packet_reply_open(gdbctx); packet_reply_open(gdbctx);
packet_reply_hex_to(gdbctx, buffer, strlen(buffer)); packet_reply_hex_to_str(gdbctx, buffer);
packet_reply_close(gdbctx); packet_reply_close(gdbctx);
} }
#endif #endif
...@@ -1549,7 +1558,7 @@ static enum packet_return packet_query(struct gdb_context* gdbctx) ...@@ -1549,7 +1558,7 @@ static enum packet_return packet_query(struct gdb_context* gdbctx)
packet_reply_open(gdbctx); packet_reply_open(gdbctx);
packet_reply_catc(gdbctx, 'O'); packet_reply_catc(gdbctx, 'O');
get_process_info(gdbctx, result, sizeof(result)); get_process_info(gdbctx, result, sizeof(result));
packet_reply_hex_to(gdbctx, result, strlen(result)); packet_reply_hex_to_str(gdbctx, result);
packet_reply_close(gdbctx); packet_reply_close(gdbctx);
return packet_done; return packet_done;
} }
...@@ -1589,9 +1598,10 @@ static enum packet_return packet_query(struct gdb_context* gdbctx) ...@@ -1589,9 +1598,10 @@ static enum packet_return packet_query(struct gdb_context* gdbctx)
if (gdbctx->wine_segs[0] == 0 && gdbctx->wine_segs[1] == 0 && if (gdbctx->wine_segs[0] == 0 && gdbctx->wine_segs[1] == 0 &&
gdbctx->wine_segs[2] == 0) gdbctx->wine_segs[2] == 0)
return packet_error; return packet_error;
sprintf(buf, "Text=%08lx;Data=%08lx;Bss=%08lx", snprintf(buf, sizeof(buf),
gdbctx->wine_segs[0], gdbctx->wine_segs[1], "Text=%08lx;Data=%08lx;Bss=%08lx",
gdbctx->wine_segs[2]); gdbctx->wine_segs[0], gdbctx->wine_segs[1],
gdbctx->wine_segs[2]);
return packet_reply(gdbctx, buf, -1); return packet_reply(gdbctx, buf, -1);
} }
break; break;
...@@ -1619,7 +1629,7 @@ static enum packet_return packet_query(struct gdb_context* gdbctx) ...@@ -1619,7 +1629,7 @@ static enum packet_return packet_query(struct gdb_context* gdbctx)
if (end == NULL) break; if (end == NULL) break;
get_thread_info(gdbctx, tid, result, sizeof(result)); get_thread_info(gdbctx, tid, result, sizeof(result));
packet_reply_open(gdbctx); packet_reply_open(gdbctx);
packet_reply_hex_to(gdbctx, result, strlen(result)); packet_reply_hex_to_str(gdbctx, result);
packet_reply_close(gdbctx); packet_reply_close(gdbctx);
return packet_done; return packet_done;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment