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]

[patch] Indirect access to GDB history variables


New Feature for GDB: Programmatic access to the value history.

Problem Description: Our company has a wide variety of GDB scripts used to 
analyze problems within core files. Many of these scripts will generate values
that are useful to probe into later; however, the scripts will generate a LOT
of values, or values that aren't in sequential order (you care about, say,
every third value). GDB only lets you reference previous history value either
with absolute numbers ($10, $236) or with reference to the most recently printed value ($$, $$9, etc). It sure would be nice if there was a way to be able to
access the value history by indirecting through a variable.

Feature: This patch enables users to programmatcially access the value history
through a GDB variable, by overloading the "$$" construct to contain a variable
name. For example, if my script had printed out values $10-$27, but only every
3rd one was interesting (it was a pointer I wished to examine further), I could
do the following:

	set $i=10
	while ($i < 28)
		p *$$i
		set $i+= 3
	end

... and I'd see values of $10, $13, $16 and so on. This makes it easier to
compose scripts together when debugging.

Implementation:
The meat of the change is in parse.c (write_dollar_variable) and eval.c 
(evaluate_subexp_standard).

I introduced a new operand type, OP_LAST_INTERNALVAR, which is emitted
by write_dollar_variable (parse.c) when it sees a "$$" that is NOT
followed by digits (and not alone, which is already an OP_LAST
operand). OP_LAST_INTERNALVAR should always be followed by an
OP_INTERNALVAR operand, pointing to the GDB variable which we will
indirect through.

When evaluate_subexp_standard (eval.c) sees an OP_LAST_INTERNALVAR, we just
need to evaluate the following OP_INTERNALVAR expression and take the 
value_contents of that expression, passing the results into 
access_value_history.

We have been using this modification internally for over a year on gdb 6.2
with no problems. The patch has been verified on gdb-6.6.50.20061212
(most recent weekly build) on Linux and on gdb-6.6.50.20061127 on Solaris 5.8
(couldn't get 20061212 to build).

Testing: This has been tested by hand. I've been trying to write a test
 case but have been having no luck getting the test suite to run (due to 
old versions of Tcl/expect on the systems this was developed on).

Future Directions: The obvious next step for this is to add a variable ($#?)
which indicates the current history value count, which makes this amenable to
full scripting rather than use by hand.

ChangeLog and Patch are attached.

--Steve

-- 
Steven Rodrigues           | Lost, yesterday, somewhere between sunrise and 
Member of Technical Staff  | sunset, two golden hours, each set with sixty
Network Appliance Corp.    | diamond minutes. No reward is offered, for they
steverod@netapp.com        | are gone forever. -- Horace Mann

Attachment: ChangeLog
Description: Text document

Attachment: gdb66.diffs
Description: Text document


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