Fix compiler warnings in remote debugging (#141060)

Example of fixed warnings on 32-bit Windows:

    Python\remote_debugging.c(24,53): warning C4244: 'function':
    conversion from 'uint64_t' to 'uintptr_t', possible loss of data

    Modules\_remote_debugging_module.c(789,44): warning C4244:
    'function': conversion from 'uint64_t' to 'size_t', possible loss
    of data
This commit is contained in:
Victor Stinner
2025-11-05 20:18:45 +01:00
committed by GitHub
parent 1d25b751c5
commit f458ac01ba
2 changed files with 36 additions and 36 deletions

View File

@@ -503,7 +503,7 @@ iterate_threads(
if (0 > _Py_RemoteDebug_PagedReadRemoteMemory( if (0 > _Py_RemoteDebug_PagedReadRemoteMemory(
&unwinder->handle, &unwinder->handle,
unwinder->interpreter_addr + unwinder->debug_offsets.interpreter_state.threads_main, unwinder->interpreter_addr + (uintptr_t)unwinder->debug_offsets.interpreter_state.threads_main,
sizeof(void*), sizeof(void*),
&thread_state_addr)) &thread_state_addr))
{ {
@@ -514,7 +514,7 @@ iterate_threads(
while (thread_state_addr != 0) { while (thread_state_addr != 0) {
if (0 > _Py_RemoteDebug_PagedReadRemoteMemory( if (0 > _Py_RemoteDebug_PagedReadRemoteMemory(
&unwinder->handle, &unwinder->handle,
thread_state_addr + unwinder->debug_offsets.thread_state.native_thread_id, thread_state_addr + (uintptr_t)unwinder->debug_offsets.thread_state.native_thread_id,
sizeof(tid), sizeof(tid),
&tid)) &tid))
{ {
@@ -530,7 +530,7 @@ iterate_threads(
// Move to next thread // Move to next thread
if (0 > _Py_RemoteDebug_PagedReadRemoteMemory( if (0 > _Py_RemoteDebug_PagedReadRemoteMemory(
&unwinder->handle, &unwinder->handle,
thread_state_addr + unwinder->debug_offsets.thread_state.next, thread_state_addr + (uintptr_t)unwinder->debug_offsets.thread_state.next,
sizeof(void*), sizeof(void*),
&thread_state_addr)) &thread_state_addr))
{ {
@@ -686,7 +686,7 @@ read_py_str(
return NULL; return NULL;
} }
size_t offset = unwinder->debug_offsets.unicode_object.asciiobject_size; size_t offset = (size_t)unwinder->debug_offsets.unicode_object.asciiobject_size;
res = _Py_RemoteDebug_PagedReadRemoteMemory(&unwinder->handle, address + offset, len, buf); res = _Py_RemoteDebug_PagedReadRemoteMemory(&unwinder->handle, address + offset, len, buf);
if (res < 0) { if (res < 0) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read string data from remote memory"); set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read string data from remote memory");
@@ -748,7 +748,7 @@ read_py_bytes(
return NULL; return NULL;
} }
size_t offset = unwinder->debug_offsets.bytes_object.ob_sval; size_t offset = (size_t)unwinder->debug_offsets.bytes_object.ob_sval;
res = _Py_RemoteDebug_PagedReadRemoteMemory(&unwinder->handle, address + offset, len, buf); res = _Py_RemoteDebug_PagedReadRemoteMemory(&unwinder->handle, address + offset, len, buf);
if (res < 0) { if (res < 0) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read bytes data from remote memory"); set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read bytes data from remote memory");
@@ -786,7 +786,7 @@ read_py_long(
int bytes_read = _Py_RemoteDebug_PagedReadRemoteMemory( int bytes_read = _Py_RemoteDebug_PagedReadRemoteMemory(
&unwinder->handle, &unwinder->handle,
address, address,
unwinder->debug_offsets.long_object.size, (size_t)unwinder->debug_offsets.long_object.size,
long_obj); long_obj);
if (bytes_read < 0) { if (bytes_read < 0) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read PyLongObject"); set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read PyLongObject");
@@ -823,7 +823,7 @@ read_py_long(
bytes_read = _Py_RemoteDebug_PagedReadRemoteMemory( bytes_read = _Py_RemoteDebug_PagedReadRemoteMemory(
&unwinder->handle, &unwinder->handle,
address + unwinder->debug_offsets.long_object.ob_digit, address + (uintptr_t)unwinder->debug_offsets.long_object.ob_digit,
sizeof(digit) * size, sizeof(digit) * size,
digits digits
); );
@@ -933,7 +933,7 @@ parse_task_name(
int err = _Py_RemoteDebug_PagedReadRemoteMemory( int err = _Py_RemoteDebug_PagedReadRemoteMemory(
&unwinder->handle, &unwinder->handle,
task_address, task_address,
unwinder->async_debug_offsets.asyncio_task_object.size, (size_t)unwinder->async_debug_offsets.asyncio_task_object.size,
task_obj); task_obj);
if (err < 0) { if (err < 0) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read task object"); set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read task object");
@@ -1040,7 +1040,7 @@ handle_yield_from_frame(
uintptr_t gi_await_addr_type_addr; uintptr_t gi_await_addr_type_addr;
err = read_ptr( err = read_ptr(
unwinder, unwinder,
gi_await_addr + unwinder->debug_offsets.pyobject.ob_type, gi_await_addr + (uintptr_t)unwinder->debug_offsets.pyobject.ob_type,
&gi_await_addr_type_addr); &gi_await_addr_type_addr);
if (err) { if (err) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read gi_await type address"); set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read gi_await type address");
@@ -1101,7 +1101,7 @@ parse_coro_chain(
// Parse the previous frame using the gi_iframe from local copy // Parse the previous frame using the gi_iframe from local copy
uintptr_t prev_frame; uintptr_t prev_frame;
uintptr_t gi_iframe_addr = coro_address + unwinder->debug_offsets.gen_object.gi_iframe; uintptr_t gi_iframe_addr = coro_address + (uintptr_t)unwinder->debug_offsets.gen_object.gi_iframe;
uintptr_t address_of_code_object = 0; uintptr_t address_of_code_object = 0;
if (parse_frame_object(unwinder, &name, gi_iframe_addr, &address_of_code_object, &prev_frame) < 0) { if (parse_frame_object(unwinder, &name, gi_iframe_addr, &address_of_code_object, &prev_frame) < 0) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to parse frame object in coro chain"); set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to parse frame object in coro chain");
@@ -1153,7 +1153,7 @@ create_task_result(
// Parse coroutine chain // Parse coroutine chain
if (_Py_RemoteDebug_PagedReadRemoteMemory(&unwinder->handle, task_address, if (_Py_RemoteDebug_PagedReadRemoteMemory(&unwinder->handle, task_address,
unwinder->async_debug_offsets.asyncio_task_object.size, (size_t)unwinder->async_debug_offsets.asyncio_task_object.size,
task_obj) < 0) { task_obj) < 0) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read task object for coro chain"); set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read task object for coro chain");
goto error; goto error;
@@ -1206,7 +1206,7 @@ parse_task(
err = read_char( err = read_char(
unwinder, unwinder,
task_address + unwinder->async_debug_offsets.asyncio_task_object.task_is_task, task_address + (uintptr_t)unwinder->async_debug_offsets.asyncio_task_object.task_is_task,
&is_task); &is_task);
if (err) { if (err) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read is_task flag"); set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read is_task flag");
@@ -1354,7 +1354,7 @@ process_thread_for_awaited_by(
void *context void *context
) { ) {
PyObject *result = (PyObject *)context; PyObject *result = (PyObject *)context;
uintptr_t head_addr = thread_state_addr + unwinder->async_debug_offsets.asyncio_thread_state.asyncio_tasks_head; uintptr_t head_addr = thread_state_addr + (uintptr_t)unwinder->async_debug_offsets.asyncio_thread_state.asyncio_tasks_head;
return append_awaited_by(unwinder, tid, head_addr, result); return append_awaited_by(unwinder, tid, head_addr, result);
} }
@@ -1369,7 +1369,7 @@ process_task_awaited_by(
// Read the entire TaskObj at once // Read the entire TaskObj at once
char task_obj[SIZEOF_TASK_OBJ]; char task_obj[SIZEOF_TASK_OBJ];
if (_Py_RemoteDebug_PagedReadRemoteMemory(&unwinder->handle, task_address, if (_Py_RemoteDebug_PagedReadRemoteMemory(&unwinder->handle, task_address,
unwinder->async_debug_offsets.asyncio_task_object.size, (size_t)unwinder->async_debug_offsets.asyncio_task_object.size,
task_obj) < 0) { task_obj) < 0) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read task object"); set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read task object");
return -1; return -1;
@@ -1526,7 +1526,7 @@ find_running_task_in_thread(
uintptr_t address_of_running_loop; uintptr_t address_of_running_loop;
int bytes_read = read_py_ptr( int bytes_read = read_py_ptr(
unwinder, unwinder,
thread_state_addr + unwinder->async_debug_offsets.asyncio_thread_state.asyncio_running_loop, thread_state_addr + (uintptr_t)unwinder->async_debug_offsets.asyncio_thread_state.asyncio_running_loop,
&address_of_running_loop); &address_of_running_loop);
if (bytes_read == -1) { if (bytes_read == -1) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read running loop address"); set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read running loop address");
@@ -1540,7 +1540,7 @@ find_running_task_in_thread(
int err = read_ptr( int err = read_ptr(
unwinder, unwinder,
thread_state_addr + unwinder->async_debug_offsets.asyncio_thread_state.asyncio_running_task, thread_state_addr + (uintptr_t)unwinder->async_debug_offsets.asyncio_thread_state.asyncio_running_task,
running_task_addr); running_task_addr);
if (err) { if (err) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read running task address"); set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read running task address");
@@ -1556,7 +1556,7 @@ get_task_code_object(RemoteUnwinderObject *unwinder, uintptr_t task_addr, uintpt
if(read_py_ptr( if(read_py_ptr(
unwinder, unwinder,
task_addr + unwinder->async_debug_offsets.asyncio_task_object.task_coro, task_addr + (uintptr_t)unwinder->async_debug_offsets.asyncio_task_object.task_coro,
&running_coro_addr) < 0) { &running_coro_addr) < 0) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Running task coro read failed"); set_exception_cause(unwinder, PyExc_RuntimeError, "Running task coro read failed");
return -1; return -1;
@@ -1572,7 +1572,7 @@ get_task_code_object(RemoteUnwinderObject *unwinder, uintptr_t task_addr, uintpt
// the offset leads directly to its first field: f_executable // the offset leads directly to its first field: f_executable
if (read_py_ptr( if (read_py_ptr(
unwinder, unwinder,
running_coro_addr + unwinder->debug_offsets.gen_object.gi_iframe, code_obj_addr) < 0) { running_coro_addr + (uintptr_t)unwinder->debug_offsets.gen_object.gi_iframe, code_obj_addr) < 0) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read running task code object"); set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read running task code object");
return -1; return -1;
} }
@@ -1741,7 +1741,7 @@ static bool
parse_linetable(const uintptr_t addrq, const char* linetable, int firstlineno, LocationInfo* info) parse_linetable(const uintptr_t addrq, const char* linetable, int firstlineno, LocationInfo* info)
{ {
const uint8_t* ptr = (const uint8_t*)(linetable); const uint8_t* ptr = (const uint8_t*)(linetable);
uint64_t addr = 0; uintptr_t addr = 0;
info->lineno = firstlineno; info->lineno = firstlineno;
while (*ptr != '\0') { while (*ptr != '\0') {
@@ -1870,7 +1870,7 @@ parse_code_object(RemoteUnwinderObject *unwinder,
meta->file_name = file; meta->file_name = file;
meta->linetable = linetable; meta->linetable = linetable;
meta->first_lineno = GET_MEMBER(int, code_object, unwinder->debug_offsets.code_object.firstlineno); meta->first_lineno = GET_MEMBER(int, code_object, unwinder->debug_offsets.code_object.firstlineno);
meta->addr_code_adaptive = real_address + unwinder->debug_offsets.code_object.co_code_adaptive; meta->addr_code_adaptive = real_address + (uintptr_t)unwinder->debug_offsets.code_object.co_code_adaptive;
if (unwinder && unwinder->code_object_cache && _Py_hashtable_set(unwinder->code_object_cache, key, meta) < 0) { if (unwinder && unwinder->code_object_cache && _Py_hashtable_set(unwinder->code_object_cache, key, meta) < 0) {
cached_code_metadata_destroy(meta); cached_code_metadata_destroy(meta);
@@ -2037,7 +2037,7 @@ copy_stack_chunks(RemoteUnwinderObject *unwinder,
size_t count = 0; size_t count = 0;
size_t max_chunks = 16; size_t max_chunks = 16;
if (read_ptr(unwinder, tstate_addr + unwinder->debug_offsets.thread_state.datastack_chunk, &chunk_addr)) { if (read_ptr(unwinder, tstate_addr + (uintptr_t)unwinder->debug_offsets.thread_state.datastack_chunk, &chunk_addr)) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read initial stack chunk address"); set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read initial stack chunk address");
return -1; return -1;
} }
@@ -2146,8 +2146,8 @@ populate_initial_state_data(
uintptr_t *interpreter_state, uintptr_t *interpreter_state,
uintptr_t *tstate uintptr_t *tstate
) { ) {
uint64_t interpreter_state_list_head = uintptr_t interpreter_state_list_head =
unwinder->debug_offsets.runtime_state.interpreters_head; (uintptr_t)unwinder->debug_offsets.runtime_state.interpreters_head;
uintptr_t address_of_interpreter_state; uintptr_t address_of_interpreter_state;
int bytes_read = _Py_RemoteDebug_PagedReadRemoteMemory( int bytes_read = _Py_RemoteDebug_PagedReadRemoteMemory(
@@ -2174,7 +2174,7 @@ populate_initial_state_data(
} }
uintptr_t address_of_thread = address_of_interpreter_state + uintptr_t address_of_thread = address_of_interpreter_state +
unwinder->debug_offsets.interpreter_state.threads_main; (uintptr_t)unwinder->debug_offsets.interpreter_state.threads_main;
if (_Py_RemoteDebug_PagedReadRemoteMemory( if (_Py_RemoteDebug_PagedReadRemoteMemory(
&unwinder->handle, &unwinder->handle,
@@ -2198,7 +2198,7 @@ find_running_frame(
if ((void*)address_of_thread != NULL) { if ((void*)address_of_thread != NULL) {
int err = read_ptr( int err = read_ptr(
unwinder, unwinder,
address_of_thread + unwinder->debug_offsets.thread_state.current_frame, address_of_thread + (uintptr_t)unwinder->debug_offsets.thread_state.current_frame,
frame); frame);
if (err) { if (err) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read current frame pointer"); set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read current frame pointer");
@@ -2370,7 +2370,7 @@ append_awaited_by_for_thread(
} }
uintptr_t task_addr = (uintptr_t)GET_MEMBER(uintptr_t, task_node, unwinder->debug_offsets.llist_node.next) uintptr_t task_addr = (uintptr_t)GET_MEMBER(uintptr_t, task_node, unwinder->debug_offsets.llist_node.next)
- unwinder->async_debug_offsets.asyncio_task_object.task_node; - (uintptr_t)unwinder->async_debug_offsets.asyncio_task_object.task_node;
if (process_single_task_node(unwinder, task_addr, NULL, result) < 0) { if (process_single_task_node(unwinder, task_addr, NULL, result) < 0) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to process task node in awaited_by"); set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to process task node in awaited_by");
@@ -2605,7 +2605,7 @@ get_thread_status(RemoteUnwinderObject *unwinder, uint64_t tid, uint64_t pthread
} }
SYSTEM_THREAD_INFORMATION *ti = (SYSTEM_THREAD_INFORMATION *)((char *)pi + sizeof(SYSTEM_PROCESS_INFORMATION)); SYSTEM_THREAD_INFORMATION *ti = (SYSTEM_THREAD_INFORMATION *)((char *)pi + sizeof(SYSTEM_PROCESS_INFORMATION));
for (Py_ssize_t i = 0; i < pi->NumberOfThreads; i++, ti++) { for (size_t i = 0; i < pi->NumberOfThreads; i++, ti++) {
if (ti->ClientId.UniqueThread == (HANDLE)tid) { if (ti->ClientId.UniqueThread == (HANDLE)tid) {
return ti->ThreadState != WIN32_THREADSTATE_RUNNING ? THREAD_STATE_IDLE : THREAD_STATE_RUNNING; return ti->ThreadState != WIN32_THREADSTATE_RUNNING ? THREAD_STATE_IDLE : THREAD_STATE_RUNNING;
} }
@@ -2642,7 +2642,7 @@ unwind_stack_for_thread(
char ts[SIZEOF_THREAD_STATE]; char ts[SIZEOF_THREAD_STATE];
int bytes_read = _Py_RemoteDebug_PagedReadRemoteMemory( int bytes_read = _Py_RemoteDebug_PagedReadRemoteMemory(
&unwinder->handle, *current_tstate, unwinder->debug_offsets.thread_state.size, ts); &unwinder->handle, *current_tstate, (size_t)unwinder->debug_offsets.thread_state.size, ts);
if (bytes_read < 0) { if (bytes_read < 0) {
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read thread state"); set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read thread state");
goto error; goto error;
@@ -3174,7 +3174,7 @@ _remote_debugging_RemoteUnwinder_get_all_awaited_by_impl(RemoteUnwinderObject *s
} }
uintptr_t head_addr = self->interpreter_addr uintptr_t head_addr = self->interpreter_addr
+ self->async_debug_offsets.asyncio_interpreter_state.asyncio_tasks_head; + (uintptr_t)self->async_debug_offsets.asyncio_interpreter_state.asyncio_tasks_head;
// On top of a per-thread task lists used by default by asyncio to avoid // On top of a per-thread task lists used by default by asyncio to avoid
// contention, there is also a fallback per-interpreter list of tasks; // contention, there is also a fallback per-interpreter list of tasks;

View File

@@ -19,7 +19,7 @@ cleanup_proc_handle(proc_handle_t *handle) {
} }
static int static int
read_memory(proc_handle_t *handle, uint64_t remote_address, size_t len, void* dst) read_memory(proc_handle_t *handle, uintptr_t remote_address, size_t len, void* dst)
{ {
return _Py_RemoteDebug_ReadRemoteMemory(handle, remote_address, len, dst); return _Py_RemoteDebug_ReadRemoteMemory(handle, remote_address, len, dst);
} }
@@ -235,7 +235,7 @@ send_exec_to_proc_handle(proc_handle_t *handle, int tid, const char *debugger_sc
int is_remote_debugging_enabled = 0; int is_remote_debugging_enabled = 0;
if (0 != read_memory( if (0 != read_memory(
handle, handle,
interpreter_state_addr + debug_offsets.debugger_support.remote_debugging_enabled, interpreter_state_addr + (uintptr_t)debug_offsets.debugger_support.remote_debugging_enabled,
sizeof(int), sizeof(int),
&is_remote_debugging_enabled)) &is_remote_debugging_enabled))
{ {
@@ -255,7 +255,7 @@ send_exec_to_proc_handle(proc_handle_t *handle, int tid, const char *debugger_sc
if (tid != 0) { if (tid != 0) {
if (0 != read_memory( if (0 != read_memory(
handle, handle,
interpreter_state_addr + debug_offsets.interpreter_state.threads_head, interpreter_state_addr + (uintptr_t)debug_offsets.interpreter_state.threads_head,
sizeof(void*), sizeof(void*),
&thread_state_addr)) &thread_state_addr))
{ {
@@ -264,7 +264,7 @@ send_exec_to_proc_handle(proc_handle_t *handle, int tid, const char *debugger_sc
while (thread_state_addr != 0) { while (thread_state_addr != 0) {
if (0 != read_memory( if (0 != read_memory(
handle, handle,
thread_state_addr + debug_offsets.thread_state.native_thread_id, thread_state_addr + (uintptr_t)debug_offsets.thread_state.native_thread_id,
sizeof(this_tid), sizeof(this_tid),
&this_tid)) &this_tid))
{ {
@@ -277,7 +277,7 @@ send_exec_to_proc_handle(proc_handle_t *handle, int tid, const char *debugger_sc
if (0 != read_memory( if (0 != read_memory(
handle, handle,
thread_state_addr + debug_offsets.thread_state.next, thread_state_addr + (uintptr_t)debug_offsets.thread_state.next,
sizeof(void*), sizeof(void*),
&thread_state_addr)) &thread_state_addr))
{ {
@@ -294,7 +294,7 @@ send_exec_to_proc_handle(proc_handle_t *handle, int tid, const char *debugger_sc
} else { } else {
if (0 != read_memory( if (0 != read_memory(
handle, handle,
interpreter_state_addr + debug_offsets.interpreter_state.threads_main, interpreter_state_addr + (uintptr_t)debug_offsets.interpreter_state.threads_main,
sizeof(void*), sizeof(void*),
&thread_state_addr)) &thread_state_addr))
{ {
@@ -346,7 +346,7 @@ send_exec_to_proc_handle(proc_handle_t *handle, int tid, const char *debugger_sc
uintptr_t eval_breaker; uintptr_t eval_breaker;
if (0 != read_memory( if (0 != read_memory(
handle, handle,
thread_state_addr + debug_offsets.debugger_support.eval_breaker, thread_state_addr + (uintptr_t)debug_offsets.debugger_support.eval_breaker,
sizeof(uintptr_t), sizeof(uintptr_t),
&eval_breaker)) &eval_breaker))
{ {