This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] - Exposing find_pc_line through Python API


> Date: Mon, 7 May 2012 23:41:25 +0530
> From: Siva Chandra <sivachandra@google.com>
> 
> I wanted a way to get the actual line number given a PC value using
> the Python API.  The currently available Symtab_and_line.line gives
> the line number which the user thinks the current execution is, but
> not the actual.

That "user thinks the execution is at" notion is far from being
clear to me.  See below.

> Attached is a patch which adds gdb.find_pc_line corresponding to the
> C function find_pc_line.

Thanks.

> +@defun gdb.find_pc_line (pc [, actual])
> +Return the @code{gdb.Symtab_and_line} object corresponding to the
> +@var{pc} value.  If @var{actual} is @code{True}, it returns the
                                                    ^^^^^^^^^^
"return", for consistency with the first sentence.

> +@code{gdb.Symtab_and_line} object with the actual line corresponding
> +to the pc value.  Otherwise, it returns the @code{gdb.Symtab_and_line}
                                ^^^^^^^^^^
Likewise.

> +The difference between @var{actual} being @code{True} or @code{False}
> +can be illustrated with an example.  Let a call to a function @code{func}
> +be on line 20 in a C source file as
> +
> +@smallexample
> +18  ...
> +19
> +20  func ();
> +21
> +22  return 0;
> +23
> +24  ...
> +@end smallexample
> +
> +After executing @value{GDBN} commands @code{step} followed by @code{up}
> +at line 20, the actual value of the @code{PC} register should correspond
> +to the next code line at line 22.  However, since the function
> +@code{func} has not yet been executed, the user feels that the execution
> +is still at line 20 (the call site) in the caller.

If I were that user, I would "feel" that the execution is at the first
line (or maybe in the prologue) of 'func', since PC is (in my mind)
unaffected by commands that walk the call stack.  And if you are
talking about the value of PC saved in the frame of the caller of
'func', then saying that line 22 is the "actual" location is again
confusing, because execution did not yet reach that point.

So I have hard time understanding why we need the distinction.  And
since you say that the current Symtab_and_line.line gives the second
alternatives, I'm confused even more.

It's possible that I'm the only confused person here, but in that
case, at least the example should be fixed to show and explain the
distinction more clearly and unequivocally, and also in which
situations the "actual" value is useful.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]