Skip to content

Commit 36e9f67

Browse files
authored
[3.14] Fix compiler warnings in remote debugging (#141060) (#141067)
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 (cherry picked from commit f458ac0)
1 parent 8675f55 commit 36e9f67

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

Modules/_remote_debugging_module.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ iterate_threads(
440440

441441
if (0 > _Py_RemoteDebug_PagedReadRemoteMemory(
442442
&unwinder->handle,
443-
unwinder->interpreter_addr + unwinder->debug_offsets.interpreter_state.threads_main,
443+
unwinder->interpreter_addr + (uintptr_t)unwinder->debug_offsets.interpreter_state.threads_main,
444444
sizeof(void*),
445445
&thread_state_addr))
446446
{
@@ -451,7 +451,7 @@ iterate_threads(
451451
while (thread_state_addr != 0) {
452452
if (0 > _Py_RemoteDebug_PagedReadRemoteMemory(
453453
&unwinder->handle,
454-
thread_state_addr + unwinder->debug_offsets.thread_state.native_thread_id,
454+
thread_state_addr + (uintptr_t)unwinder->debug_offsets.thread_state.native_thread_id,
455455
sizeof(tid),
456456
&tid))
457457
{
@@ -467,7 +467,7 @@ iterate_threads(
467467
// Move to next thread
468468
if (0 > _Py_RemoteDebug_PagedReadRemoteMemory(
469469
&unwinder->handle,
470-
thread_state_addr + unwinder->debug_offsets.thread_state.next,
470+
thread_state_addr + (uintptr_t)unwinder->debug_offsets.thread_state.next,
471471
sizeof(void*),
472472
&thread_state_addr))
473473
{
@@ -623,7 +623,7 @@ read_py_str(
623623
return NULL;
624624
}
625625

626-
size_t offset = unwinder->debug_offsets.unicode_object.asciiobject_size;
626+
size_t offset = (size_t)unwinder->debug_offsets.unicode_object.asciiobject_size;
627627
res = _Py_RemoteDebug_PagedReadRemoteMemory(&unwinder->handle, address + offset, len, buf);
628628
if (res < 0) {
629629
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read string data from remote memory");
@@ -685,7 +685,7 @@ read_py_bytes(
685685
return NULL;
686686
}
687687

688-
size_t offset = unwinder->debug_offsets.bytes_object.ob_sval;
688+
size_t offset = (size_t)unwinder->debug_offsets.bytes_object.ob_sval;
689689
res = _Py_RemoteDebug_PagedReadRemoteMemory(&unwinder->handle, address + offset, len, buf);
690690
if (res < 0) {
691691
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read bytes data from remote memory");
@@ -723,7 +723,7 @@ read_py_long(
723723
int bytes_read = _Py_RemoteDebug_PagedReadRemoteMemory(
724724
&unwinder->handle,
725725
address,
726-
unwinder->debug_offsets.long_object.size,
726+
(size_t)unwinder->debug_offsets.long_object.size,
727727
long_obj);
728728
if (bytes_read < 0) {
729729
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read PyLongObject");
@@ -760,7 +760,7 @@ read_py_long(
760760

761761
bytes_read = _Py_RemoteDebug_PagedReadRemoteMemory(
762762
&unwinder->handle,
763-
address + unwinder->debug_offsets.long_object.ob_digit,
763+
address + (uintptr_t)unwinder->debug_offsets.long_object.ob_digit,
764764
sizeof(digit) * size,
765765
digits
766766
);
@@ -870,7 +870,7 @@ parse_task_name(
870870
int err = _Py_RemoteDebug_PagedReadRemoteMemory(
871871
&unwinder->handle,
872872
task_address,
873-
unwinder->async_debug_offsets.asyncio_task_object.size,
873+
(size_t)unwinder->async_debug_offsets.asyncio_task_object.size,
874874
task_obj);
875875
if (err < 0) {
876876
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read task object");
@@ -977,7 +977,7 @@ handle_yield_from_frame(
977977
uintptr_t gi_await_addr_type_addr;
978978
err = read_ptr(
979979
unwinder,
980-
gi_await_addr + unwinder->debug_offsets.pyobject.ob_type,
980+
gi_await_addr + (uintptr_t)unwinder->debug_offsets.pyobject.ob_type,
981981
&gi_await_addr_type_addr);
982982
if (err) {
983983
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read gi_await type address");
@@ -1038,7 +1038,7 @@ parse_coro_chain(
10381038

10391039
// Parse the previous frame using the gi_iframe from local copy
10401040
uintptr_t prev_frame;
1041-
uintptr_t gi_iframe_addr = coro_address + unwinder->debug_offsets.gen_object.gi_iframe;
1041+
uintptr_t gi_iframe_addr = coro_address + (uintptr_t)unwinder->debug_offsets.gen_object.gi_iframe;
10421042
uintptr_t address_of_code_object = 0;
10431043
if (parse_frame_object(unwinder, &name, gi_iframe_addr, &address_of_code_object, &prev_frame) < 0) {
10441044
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to parse frame object in coro chain");
@@ -1090,7 +1090,7 @@ create_task_result(
10901090

10911091
// Parse coroutine chain
10921092
if (_Py_RemoteDebug_PagedReadRemoteMemory(&unwinder->handle, task_address,
1093-
unwinder->async_debug_offsets.asyncio_task_object.size,
1093+
(size_t)unwinder->async_debug_offsets.asyncio_task_object.size,
10941094
task_obj) < 0) {
10951095
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read task object for coro chain");
10961096
goto error;
@@ -1143,7 +1143,7 @@ parse_task(
11431143

11441144
err = read_char(
11451145
unwinder,
1146-
task_address + unwinder->async_debug_offsets.asyncio_task_object.task_is_task,
1146+
task_address + (uintptr_t)unwinder->async_debug_offsets.asyncio_task_object.task_is_task,
11471147
&is_task);
11481148
if (err) {
11491149
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read is_task flag");
@@ -1291,7 +1291,7 @@ process_thread_for_awaited_by(
12911291
void *context
12921292
) {
12931293
PyObject *result = (PyObject *)context;
1294-
uintptr_t head_addr = thread_state_addr + unwinder->async_debug_offsets.asyncio_thread_state.asyncio_tasks_head;
1294+
uintptr_t head_addr = thread_state_addr + (uintptr_t)unwinder->async_debug_offsets.asyncio_thread_state.asyncio_tasks_head;
12951295
return append_awaited_by(unwinder, tid, head_addr, result);
12961296
}
12971297

@@ -1306,7 +1306,7 @@ process_task_awaited_by(
13061306
// Read the entire TaskObj at once
13071307
char task_obj[SIZEOF_TASK_OBJ];
13081308
if (_Py_RemoteDebug_PagedReadRemoteMemory(&unwinder->handle, task_address,
1309-
unwinder->async_debug_offsets.asyncio_task_object.size,
1309+
(size_t)unwinder->async_debug_offsets.asyncio_task_object.size,
13101310
task_obj) < 0) {
13111311
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read task object");
13121312
return -1;
@@ -1463,7 +1463,7 @@ find_running_task_in_thread(
14631463
uintptr_t address_of_running_loop;
14641464
int bytes_read = read_py_ptr(
14651465
unwinder,
1466-
thread_state_addr + unwinder->async_debug_offsets.asyncio_thread_state.asyncio_running_loop,
1466+
thread_state_addr + (uintptr_t)unwinder->async_debug_offsets.asyncio_thread_state.asyncio_running_loop,
14671467
&address_of_running_loop);
14681468
if (bytes_read == -1) {
14691469
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read running loop address");
@@ -1477,7 +1477,7 @@ find_running_task_in_thread(
14771477

14781478
int err = read_ptr(
14791479
unwinder,
1480-
thread_state_addr + unwinder->async_debug_offsets.asyncio_thread_state.asyncio_running_task,
1480+
thread_state_addr + (uintptr_t)unwinder->async_debug_offsets.asyncio_thread_state.asyncio_running_task,
14811481
running_task_addr);
14821482
if (err) {
14831483
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read running task address");
@@ -1493,7 +1493,7 @@ get_task_code_object(RemoteUnwinderObject *unwinder, uintptr_t task_addr, uintpt
14931493

14941494
if(read_py_ptr(
14951495
unwinder,
1496-
task_addr + unwinder->async_debug_offsets.asyncio_task_object.task_coro,
1496+
task_addr + (uintptr_t)unwinder->async_debug_offsets.asyncio_task_object.task_coro,
14971497
&running_coro_addr) < 0) {
14981498
set_exception_cause(unwinder, PyExc_RuntimeError, "Running task coro read failed");
14991499
return -1;
@@ -1509,7 +1509,7 @@ get_task_code_object(RemoteUnwinderObject *unwinder, uintptr_t task_addr, uintpt
15091509
// the offset leads directly to its first field: f_executable
15101510
if (read_py_ptr(
15111511
unwinder,
1512-
running_coro_addr + unwinder->debug_offsets.gen_object.gi_iframe, code_obj_addr) < 0) {
1512+
running_coro_addr + (uintptr_t)unwinder->debug_offsets.gen_object.gi_iframe, code_obj_addr) < 0) {
15131513
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read running task code object");
15141514
return -1;
15151515
}
@@ -1657,7 +1657,7 @@ static bool
16571657
parse_linetable(const uintptr_t addrq, const char* linetable, int firstlineno, LocationInfo* info)
16581658
{
16591659
const uint8_t* ptr = (const uint8_t*)(linetable);
1660-
uint64_t addr = 0;
1660+
uintptr_t addr = 0;
16611661
info->lineno = firstlineno;
16621662

16631663
while (*ptr != '\0') {
@@ -1785,7 +1785,7 @@ parse_code_object(RemoteUnwinderObject *unwinder,
17851785
meta->file_name = file;
17861786
meta->linetable = linetable;
17871787
meta->first_lineno = GET_MEMBER(int, code_object, unwinder->debug_offsets.code_object.firstlineno);
1788-
meta->addr_code_adaptive = real_address + unwinder->debug_offsets.code_object.co_code_adaptive;
1788+
meta->addr_code_adaptive = real_address + (uintptr_t)unwinder->debug_offsets.code_object.co_code_adaptive;
17891789

17901790
if (unwinder && unwinder->code_object_cache && _Py_hashtable_set(unwinder->code_object_cache, key, meta) < 0) {
17911791
cached_code_metadata_destroy(meta);
@@ -1952,7 +1952,7 @@ copy_stack_chunks(RemoteUnwinderObject *unwinder,
19521952
size_t count = 0;
19531953
size_t max_chunks = 16;
19541954

1955-
if (read_ptr(unwinder, tstate_addr + unwinder->debug_offsets.thread_state.datastack_chunk, &chunk_addr)) {
1955+
if (read_ptr(unwinder, tstate_addr + (uintptr_t)unwinder->debug_offsets.thread_state.datastack_chunk, &chunk_addr)) {
19561956
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read initial stack chunk address");
19571957
return -1;
19581958
}
@@ -2061,8 +2061,8 @@ populate_initial_state_data(
20612061
uintptr_t *interpreter_state,
20622062
uintptr_t *tstate
20632063
) {
2064-
uint64_t interpreter_state_list_head =
2065-
unwinder->debug_offsets.runtime_state.interpreters_head;
2064+
uintptr_t interpreter_state_list_head =
2065+
(uintptr_t)unwinder->debug_offsets.runtime_state.interpreters_head;
20662066

20672067
uintptr_t address_of_interpreter_state;
20682068
int bytes_read = _Py_RemoteDebug_PagedReadRemoteMemory(
@@ -2089,7 +2089,7 @@ populate_initial_state_data(
20892089
}
20902090

20912091
uintptr_t address_of_thread = address_of_interpreter_state +
2092-
unwinder->debug_offsets.interpreter_state.threads_main;
2092+
(uintptr_t)unwinder->debug_offsets.interpreter_state.threads_main;
20932093

20942094
if (_Py_RemoteDebug_PagedReadRemoteMemory(
20952095
&unwinder->handle,
@@ -2113,7 +2113,7 @@ find_running_frame(
21132113
if ((void*)address_of_thread != NULL) {
21142114
int err = read_ptr(
21152115
unwinder,
2116-
address_of_thread + unwinder->debug_offsets.thread_state.current_frame,
2116+
address_of_thread + (uintptr_t)unwinder->debug_offsets.thread_state.current_frame,
21172117
frame);
21182118
if (err) {
21192119
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read current frame pointer");
@@ -2285,7 +2285,7 @@ append_awaited_by_for_thread(
22852285
}
22862286

22872287
uintptr_t task_addr = (uintptr_t)GET_MEMBER(uintptr_t, task_node, unwinder->debug_offsets.llist_node.next)
2288-
- unwinder->async_debug_offsets.asyncio_task_object.task_node;
2288+
- (uintptr_t)unwinder->async_debug_offsets.asyncio_task_object.task_node;
22892289

22902290
if (process_single_task_node(unwinder, task_addr, NULL, result) < 0) {
22912291
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to process task node in awaited_by");
@@ -2428,7 +2428,7 @@ unwind_stack_for_thread(
24282428

24292429
char ts[SIZEOF_THREAD_STATE];
24302430
int bytes_read = _Py_RemoteDebug_PagedReadRemoteMemory(
2431-
&unwinder->handle, *current_tstate, unwinder->debug_offsets.thread_state.size, ts);
2431+
&unwinder->handle, *current_tstate, (size_t)unwinder->debug_offsets.thread_state.size, ts);
24322432
if (bytes_read < 0) {
24332433
set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to read thread state");
24342434
goto error;
@@ -2830,7 +2830,7 @@ _remote_debugging_RemoteUnwinder_get_all_awaited_by_impl(RemoteUnwinderObject *s
28302830
}
28312831

28322832
uintptr_t head_addr = self->interpreter_addr
2833-
+ self->async_debug_offsets.asyncio_interpreter_state.asyncio_tasks_head;
2833+
+ (uintptr_t)self->async_debug_offsets.asyncio_interpreter_state.asyncio_tasks_head;
28342834

28352835
// On top of a per-thread task lists used by default by asyncio to avoid
28362836
// contention, there is also a fallback per-interpreter list of tasks;

Python/remote_debugging.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ cleanup_proc_handle(proc_handle_t *handle) {
1919
}
2020

2121
static int
22-
read_memory(proc_handle_t *handle, uint64_t remote_address, size_t len, void* dst)
22+
read_memory(proc_handle_t *handle, uintptr_t remote_address, size_t len, void* dst)
2323
{
2424
return _Py_RemoteDebug_ReadRemoteMemory(handle, remote_address, len, dst);
2525
}
@@ -235,7 +235,7 @@ send_exec_to_proc_handle(proc_handle_t *handle, int tid, const char *debugger_sc
235235
int is_remote_debugging_enabled = 0;
236236
if (0 != read_memory(
237237
handle,
238-
interpreter_state_addr + debug_offsets.debugger_support.remote_debugging_enabled,
238+
interpreter_state_addr + (uintptr_t)debug_offsets.debugger_support.remote_debugging_enabled,
239239
sizeof(int),
240240
&is_remote_debugging_enabled))
241241
{
@@ -255,7 +255,7 @@ send_exec_to_proc_handle(proc_handle_t *handle, int tid, const char *debugger_sc
255255
if (tid != 0) {
256256
if (0 != read_memory(
257257
handle,
258-
interpreter_state_addr + debug_offsets.interpreter_state.threads_head,
258+
interpreter_state_addr + (uintptr_t)debug_offsets.interpreter_state.threads_head,
259259
sizeof(void*),
260260
&thread_state_addr))
261261
{
@@ -264,7 +264,7 @@ send_exec_to_proc_handle(proc_handle_t *handle, int tid, const char *debugger_sc
264264
while (thread_state_addr != 0) {
265265
if (0 != read_memory(
266266
handle,
267-
thread_state_addr + debug_offsets.thread_state.native_thread_id,
267+
thread_state_addr + (uintptr_t)debug_offsets.thread_state.native_thread_id,
268268
sizeof(this_tid),
269269
&this_tid))
270270
{
@@ -277,7 +277,7 @@ send_exec_to_proc_handle(proc_handle_t *handle, int tid, const char *debugger_sc
277277

278278
if (0 != read_memory(
279279
handle,
280-
thread_state_addr + debug_offsets.thread_state.next,
280+
thread_state_addr + (uintptr_t)debug_offsets.thread_state.next,
281281
sizeof(void*),
282282
&thread_state_addr))
283283
{
@@ -294,7 +294,7 @@ send_exec_to_proc_handle(proc_handle_t *handle, int tid, const char *debugger_sc
294294
} else {
295295
if (0 != read_memory(
296296
handle,
297-
interpreter_state_addr + debug_offsets.interpreter_state.threads_main,
297+
interpreter_state_addr + (uintptr_t)debug_offsets.interpreter_state.threads_main,
298298
sizeof(void*),
299299
&thread_state_addr))
300300
{
@@ -346,7 +346,7 @@ send_exec_to_proc_handle(proc_handle_t *handle, int tid, const char *debugger_sc
346346
uintptr_t eval_breaker;
347347
if (0 != read_memory(
348348
handle,
349-
thread_state_addr + debug_offsets.debugger_support.eval_breaker,
349+
thread_state_addr + (uintptr_t)debug_offsets.debugger_support.eval_breaker,
350350
sizeof(uintptr_t),
351351
&eval_breaker))
352352
{

0 commit comments

Comments
 (0)