Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #68862 > unrolled thread
| Started by | Wesley <nispray@gmail.com> |
|---|---|
| First post | 2014-03-24 03:20 -0700 |
| Last post | 2014-03-26 18:04 -0700 |
| Articles | 7 — 3 participants |
Back to article view | Back to comp.lang.python
gdb python how to output integer for examine memory Wesley <nispray@gmail.com> - 2014-03-24 03:20 -0700
Re:gdb python how to output integer for examine memory Dave Angel <davea@davea.name> - 2014-03-24 08:22 -0400
Re: gdb python how to output integer for examine memory Wesley <nispray@gmail.com> - 2014-03-24 06:37 -0700
Re: gdb python how to output integer for examine memory dieter <dieter@handshake.de> - 2014-03-25 08:49 +0100
Re: gdb python how to output integer for examine memory Wesley <nispray@gmail.com> - 2014-03-25 01:07 -0700
Re: gdb python how to output integer for examine memory dieter <dieter@handshake.de> - 2014-03-26 08:10 +0100
Re: gdb python how to output integer for examine memory Wesley <nispray@gmail.com> - 2014-03-26 18:04 -0700
| From | Wesley <nispray@gmail.com> |
|---|---|
| Date | 2014-03-24 03:20 -0700 |
| Subject | gdb python how to output integer for examine memory |
| Message-ID | <e1e8c3a2-5d8d-4aae-9a5d-82af79be8c4c@googlegroups.com> |
Hi all,
I am trying to use gdb debug python script.
I am using gdb7.7 and python2.7.6, here is my simple test script:
import time
def next(i):
time.sleep(10)
i = 1 - i
i = 1
while True:
next(i)
When this script running, gdb attach to it, and here is snippet:
(gdb) py-bt
#5 Frame 0x201e130, for file test.py, line 6, in next (i=1)
Python Exception <type 'exceptions.IOError'> (2, '\xe6\xb2\xa1\xe6\x9c\x89\xe9\x82\xa3\xe4\xb8\xaa\xe6\x96\x87\xe4\xbb\xb6\xe6\x88\x96\xe7\x9b\xae\xe5\xbd\x95', 'test.py'):
Error occurred in Python command: (2, '\xe6\xb2\xa1\xe6\x9c\x89\xe9\x82\xa3\xe4\xb8\xaa\xe6\x96\x87\xe4\xbb\xb6\xe6\x88\x96\xe7\x9b\xae\xe5\xbd\x95', 'test.py')
(gdb) frame 5
#5 0x00000000004d01a7 in PyEval_EvalFrameEx (f=Frame 0x201e130, for file test.py, line 6, in next (i=1), throwflag=0) at Python/ceval.c:2666
2666 x = call_function(&sp, oparg);
(gdb) py-locals
i = 1
(gdb) pyo i
No symbol "i" in current context.
(gdb)
No symbol "i" in current context.
(gdb) p f->f_localsplus
$1 = {1}
(gdb) p f->f_localsplus[0]
$2 = 1
(gdb) p &(f->f_localsplus[0])
$3 = (PyObject **) 0x201e2b8
(gdb) x/d 0x201e2b8
0x201e2b8: 31304528
(gdb) p sizeof(f->f_localsplus[0])
$4 = 8
(gdb) x/dg 0x201e2b8
0x201e2b8: 31304528
(gdb) x/dw 0x201e2b8
0x201e2b8: 31304528
(gdb)
So, the latter several commands, I wannted to check memory content, but , how to output integer 1?
Thanks.
Wesley
[toc] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2014-03-24 08:22 -0400 |
| Message-ID | <mailman.8447.1395663507.18130.python-list@python.org> |
| In reply to | #68862 |
Wesley <nispray@gmail.com> Wrote in message:
> Hi all,
> I am trying to use gdb debug python script.
> I am using gdb7.7 and python2.7.6, here is my simple test script:
> import time
>
> def next(i):
> time.sleep(10)
> i = 1 - i
>
> i = 1
> while True:
> next(i)
> When this script running, gdb attach to it, and here is snippet:
>
I cannot help with gdb, but I can point out that you have two
separate variables here. Decrement ing the local has no effect on
the global value.
The preferred way is to return any values from the function that
you want to use after it exits.
def next(i):
time.sleep(10)
i = 1 - i
return i
i = 1
while True:
i =next(i)
Another possibility, generally a bad idea, is declaring i global
in the function.
--
DaveA
[toc] | [prev] | [next] | [standalone]
| From | Wesley <nispray@gmail.com> |
|---|---|
| Date | 2014-03-24 06:37 -0700 |
| Message-ID | <cb8140fb-ee67-453c-ab21-24e24e705cb4@googlegroups.com> |
| In reply to | #68873 |
Hi Dave, Thanks for your response. It's just a simple script for test:-) My concern is use gdb to monitor variable in memory within python process. For details, in my origin post, just wanna why cannot output interger value from the address. Maybe here is not right for gdb python question..but seems I cannot post question at another gdb group. So, post here, since it's also related to python,in case anyone knowns this. Sorry for that. Wesley 在 2014年3月24日星期一UTC+8下午8时22分59秒,Dave Angel写道: > Wesley <nispray@gmail.com> Wrote in message: > > > Hi all, > > > I am trying to use gdb debug python script. > > > I am using gdb7.7 and python2.7.6, here is my simple test script: > > > import time > > > > > > def next(i): > > > time.sleep(10) > > > i = 1 - i > > > > > > i = 1 > > > while True: > > > next(i) > > > When this script running, gdb attach to it, and here is snippet: > > > > > > > I cannot help with gdb, but I can point out that you have two > > separate variables here. Decrement ing the local has no effect on > > the global value. > > > > The preferred way is to return any values from the function that > > you want to use after it exits. > > def next(i): > > time.sleep(10) > > i = 1 - i > > return i > > > > i = 1 > > while True: > > i =next(i) > > > > Another possibility, generally a bad idea, is declaring i global > > in the function. > > > > -- > > DaveA
[toc] | [prev] | [next] | [standalone]
| From | dieter <dieter@handshake.de> |
|---|---|
| Date | 2014-03-25 08:49 +0100 |
| Message-ID | <mailman.8505.1395733762.18130.python-list@python.org> |
| In reply to | #68862 |
Wesley <nispray@gmail.com> writes: > I am trying to use gdb debug python script. > I am using gdb7.7 and python2.7.6, here is my simple test script: > import time > > def next(i): > time.sleep(10) > i = 1 - i > > i = 1 > while True: > next(i) > When this script running, gdb attach to it, and here is snippet: > > ... > (gdb) frame 5 > #5 0x00000000004d01a7 in PyEval_EvalFrameEx (f=Frame 0x201e130, for file test.py, line 6, in next (i=1), throwflag=0) at Python/ceval.c:2666 > 2666 x = call_function(&sp, oparg); > (gdb) py-locals > i = 1 > (gdb) pyo i > No symbol "i" in current context. Quite a lot of time has passed since I last had to debug Python processes at C level -- thus, my memory may be unreliable. When I remember right, then "pyo" is used to interprete a C level variable as a Python object (and print it) -- not a Python level variable. In your case, "i" is a Python level variable. You must carefully distinguish between the C level and the Python level. Some commands expect C level names/objects; others may expect Python level names/objects. To learn how you can obtain the value of a Python variable, I see two approaches: look through the list of provided commands (and their documentation) and try to figure out which might be applicable and then may some tests; or look at the implementation of "py-locals" and use this knowledge to define you own command (for this, you will also need to understand the gdb language to define commands).
[toc] | [prev] | [next] | [standalone]
| From | Wesley <nispray@gmail.com> |
|---|---|
| Date | 2014-03-25 01:07 -0700 |
| Message-ID | <2aa794ce-7cc1-4d24-a30b-3fb17b89e33f@googlegroups.com> |
| In reply to | #68994 |
在 2014年3月25日星期二UTC+8下午3时49分09秒,dieter写道: > Wesley <nispray@gmail.com> writes: > > > > > I am trying to use gdb debug python script. > > > I am using gdb7.7 and python2.7.6, here is my simple test script: > > > import time > > > > > > def next(i): > > > time.sleep(10) > > > i = 1 - i > > > > > > i = 1 > > > while True: > > > next(i) > > > When this script running, gdb attach to it, and here is snippet: > > > > > > ... > > > (gdb) frame 5 > > > #5 0x00000000004d01a7 in PyEval_EvalFrameEx (f=Frame 0x201e130, for file test.py, line 6, in next (i=1), throwflag=0) at Python/ceval.c:2666 > > > 2666 x = call_function(&sp, oparg); > > > (gdb) py-locals > > > i = 1 > > > (gdb) pyo i > > > No symbol "i" in current context. > > > > Quite a lot of time has passed since I last had to debug Python > > processes at C level -- thus, my memory may be unreliable. > > > > When I remember right, then "pyo" is used to interprete > > a C level variable as a Python object (and print it) -- not > > a Python level variable. In your case, "i" is a Python level variable. > > > > You must carefully distinguish between the C level and the Python level. > > Some commands expect C level names/objects; > > others may expect Python level names/objects. > > > > To learn how you can obtain the value of a Python variable, > > I see two approaches: look through the list of provided commands > > (and their documentation) and try to figure out which might be applicable > > and then may some tests; or look at the implementation of "py-locals" > > and use this knowledge to define you own command (for this, > > you will also need to understand the gdb language to define commands). Hi Dieter, Thanks. Actually, I can now see the varialbe names at Python level and C level. I just want to verify x command to monitor the memory content. So, in my origin post, I can get variable i's address, and see the value is 1, then, I wanna have a try x command, the issue is, when use x/format i's address, the output is not 1, but other things:-(
[toc] | [prev] | [next] | [standalone]
| From | dieter <dieter@handshake.de> |
|---|---|
| Date | 2014-03-26 08:10 +0100 |
| Message-ID | <mailman.8563.1395817836.18130.python-list@python.org> |
| In reply to | #68997 |
Wesley <nispray@gmail.com> writes: > ... > Actually, I can now see the varialbe names at Python level and C level. > I just want to verify x command to monitor the memory content. > So, in my origin post, I can get variable i's address, and see the value is 1, > then, I wanna have a try x command, the issue is, when use x/format i's address, the output is not 1, but other things:-( All Python objects start (at C level) with a header (containing the reference count, a pointer to the associated type and maybe other things); the "real" value starts behind this header. This means, to see the "1" in your example, you must skip the associated object header -- either in the output or by adding the size of the header to the initial address.
[toc] | [prev] | [next] | [standalone]
| From | Wesley <nispray@gmail.com> |
|---|---|
| Date | 2014-03-26 18:04 -0700 |
| Message-ID | <241236ba-029a-4206-b5a1-f60bd19e56c9@googlegroups.com> |
| In reply to | #69104 |
在 2014年3月26日星期三UTC+8下午3时10分23秒,dieter写道: > Wesley <nispray@gmail.com> writes: > > > ... > > > Actually, I can now see the varialbe names at Python level and C level. > > > I just want to verify x command to monitor the memory content. > > > So, in my origin post, I can get variable i's address, and see the value is 1, > > > then, I wanna have a try x command, the issue is, when use x/format i's address, the output is not 1, but other things:-( > > > > All Python objects start (at C level) with a header (containing > > the reference count, a pointer to the associated type and > > maybe other things); the "real" value starts behind this header. > > > > This means, to see the "1" in your example, you must skip the > > associated object header -- either in the output or by adding > > the size of the header to the initial address. Most like this. I will try later.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web