7 """ This module evaluates function parameters of those OMPD callbacks that need GDB API calls.
10 """ Have the debugger print a string.
15 # args is a tuple with just one string element
16 print_string
= args
[0]
17 gdb
.execute('printf "%s\n"' % args
[0])
20 """ Look up the address of a global symbol in the target.
25 # args is a tuple consisting of thread_id and symbol_name
29 gdb
.execute("thread %d\n" % thread_id
, to_string
=True)
30 return int(gdb
.parse_and_eval("&" + symbol_name
))
33 """ Read string from the target and copy it into the provided buffer.
37 def _read_string(*args
):
38 # args is a tuple with just the source address
41 buf
= gdb
.parse_and_eval("(unsigned char*)%li" % addr
).string()
47 """ Read memory from the target and copy it into the provided buffer.
52 # args is a tuple consisting of address and number of bytes to be read
55 # print("_read(%i,%i)"%(addr, nbytes))
58 buf
= gdb
.parse_and_eval("(unsigned char*)%li" % addr
)
59 for i
in range(nbytes
):
60 ret_buf
.append(int(buf
[i
]))
62 # traceback.print_exc()
66 """ Get thread-specific context.
67 Return -1 if no match is found.
71 def _thread_context(*args
):
72 # args is a tuple consisting of thread_id and the thread kind
80 info
= gdb
.execute("info threads", to_string
=True).splitlines()
84 m
= re
.search(r
"(0x[a-fA-F0-9]+)", line
)
86 m
= re
.search(r
"\([^)]*?(\d+)[^)]*?\)", line
)
89 pid
= int(m
.group(1), 0)
91 return int(line
[2:6], 0)
95 """ Test info threads / list threads / how to split output to get thread id
100 def _test_threads(*args
):
101 info
= gdb
.execute("info threads", to_string
=True).splitlines()
102 for line
in info
[1:]:
103 content
= line
.split()
105 # fetch pointer to id
106 if content
[0].startswith("*"):
107 thread_id
= content
[3]
109 thread_id
= content
[2]
110 sizeof_tid
= sys
.getsizeof(thread_id
)