* environment for 'shell' command
@ 2002-07-17 9:50 Jason Kraftcheck
2002-09-09 11:45 ` Andrew Cagney
0 siblings, 1 reply; 3+ messages in thread
From: Jason Kraftcheck @ 2002-07-17 9:50 UTC (permalink / raw)
To: gdb
Hi,
I would like the ability to pass the file name and line number of the
source corresponding to the selected stack frame to a program started
via the 'shell' command. I could not find any way to do this in gdb.
If there is a way to do this, please let me know (and disregard the rest
of this message.) I decided to add this functionality but I am
unfimiliar with the internal workings of gdb. The following is a
description of what I did to implement this. I'd really appreciate any
suggestions on better ways to implement this, error conditions I'm not
handling, etc.
The simplest way I could come up with to do this is to put the values in
environmental variables immediately before executing the command.
Specifically, setting gdb_stack_dir, gdb_stack_file, and gdb_stack_line
to the values from a struct symtab_and_line. I use this for defining
things like a 'view' command that highlights the current location in the
source in a text editor:
define view
shell if [ x$gdb_stack_file != x ]; then \
nc -line $gdb_stack_line $gdb_stack_dir$gdb_stack_file; \
fi
end
I added the following function to stack.c to get a symtab_and_line
struct for the selected frame:
/* Get a symtab_and_line for the selected stack frame. */
struct symtab_and_line
find_selected_line (void)
{
struct symtab_and_line sal;
INIT_SAL( &sal );
if( selected_frame != NULL )
sal = find_pc_line(selected_frame->pc,
selected_frame->next
&& !selected_frame->next->signal_handler_caller
&& !frame_in_dummy (selected_frame->next));
return sal;
}
I added a function 'set_shell_environment' to cli/cli-cmds.c and added
calls to that function in 'shell_escape'.
#define SHELL_ENV "gdb_stack_"
static void
set_shell_environment()
{
char buffer[16];
struct symtab_and_line sal = find_selected_line();
unsetenv (SHELL_ENV "file");
unsetenv (SHELL_ENV "dir");
unsetenv (SHELL_ENV "line");
if (sal.symtab && sal.symtab->filename && sal.symtab->dirname)
{
sprintf (buffer, "%d", sal.line);
setenv (SHELL_ENV "line", buffer, 1);
setenv (SHLLL_ENV "dir", sal.symtab->dirname, 1);
setenv (SHELL_ENV "file", sal.symtab->filename, 1);
}
}
thanks,
--
Jason Kraftcheck
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: environment for 'shell' command
2002-07-17 9:50 environment for 'shell' command Jason Kraftcheck
@ 2002-09-09 11:45 ` Andrew Cagney
2002-09-09 13:23 ` Daniel Jacobowitz
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Cagney @ 2002-09-09 11:45 UTC (permalink / raw)
To: kraftche; +Cc: gdb
> Hi,
>
> I would like the ability to pass the file name and line number of the
> source corresponding to the selected stack frame to a program started
> via the 'shell' command. I could not find any way to do this in gdb.
> If there is a way to do this, please let me know (and disregard the rest
> of this message.) I decided to add this functionality but I am
> unfimiliar with the internal workings of gdb. The following is a
> description of what I did to implement this. I'd really appreciate any
> suggestions on better ways to implement this, error conditions I'm not
> handling, etc.
Off hand I can think of two ways to handle this:
-- extend what you've proposed by including commands to explicitly
manipulate the exported environment, vis:
(gdb) command-to-set-shell-env VARIABLE VALUE
(gdb) shell printenv VARIABLE
VARIABLE=VALUE
(gdb)
where VALUE is something that GDB could evaluate.
As I suspect you discovered, there currently isn't a mechanism for
refering to the current SAL from GDB's command line.
I think it is better to have explicit commands to manipulate the
exported environment as that will help make things more transparent. A
few defaults wouldn't hurt of course.
-- extend ``shell'' or add a new command that lets expressions that GDB
evaluates be passed down to the shell. That way, something like:
(gdb) eval shell $frame.file $frame.line
would pass down the values you need. (No $frame.file and $frame.line do
not exist :-). Hmm, it appears that ``eval'' isn't taken.
Anyone?
(It's time to reach a decision on $frame, $gdbframe $gdb.frame and get
that committed :-)
Andrew
> The simplest way I could come up with to do this is to put the values in
> environmental variables immediately before executing the command.
> Specifically, setting gdb_stack_dir, gdb_stack_file, and gdb_stack_line
> to the values from a struct symtab_and_line. I use this for defining
> things like a 'view' command that highlights the current location in the
> source in a text editor:
> define view
> shell if [ x$gdb_stack_file != x ]; then \
> nc -line $gdb_stack_line $gdb_stack_dir$gdb_stack_file; \
> fi
> end
>
> I added the following function to stack.c to get a symtab_and_line
> struct for the selected frame:
>
> /* Get a symtab_and_line for the selected stack frame. */
> struct symtab_and_line
> find_selected_line (void)
> {
> struct symtab_and_line sal;
> INIT_SAL( &sal );
> if( selected_frame != NULL )
> sal = find_pc_line(selected_frame->pc,
> selected_frame->next
> && !selected_frame->next->signal_handler_caller
> && !frame_in_dummy (selected_frame->next));
> return sal;
> }
>
>
> I added a function 'set_shell_environment' to cli/cli-cmds.c and added
> calls to that function in 'shell_escape'.
>
> #define SHELL_ENV "gdb_stack_"
>
> static void
> set_shell_environment()
> {
> char buffer[16];
> struct symtab_and_line sal = find_selected_line();
>
> unsetenv (SHELL_ENV "file");
> unsetenv (SHELL_ENV "dir");
> unsetenv (SHELL_ENV "line");
>
> if (sal.symtab && sal.symtab->filename && sal.symtab->dirname)
> {
> sprintf (buffer, "%d", sal.line);
> setenv (SHELL_ENV "line", buffer, 1);
> setenv (SHLLL_ENV "dir", sal.symtab->dirname, 1);
> setenv (SHELL_ENV "file", sal.symtab->filename, 1);
> }
> }
>
> thanks,
>
> -- Jason Kraftcheck
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: environment for 'shell' command
2002-09-09 11:45 ` Andrew Cagney
@ 2002-09-09 13:23 ` Daniel Jacobowitz
0 siblings, 0 replies; 3+ messages in thread
From: Daniel Jacobowitz @ 2002-09-09 13:23 UTC (permalink / raw)
To: Andrew Cagney; +Cc: kraftche, gdb
On Mon, Sep 09, 2002 at 02:45:38PM -0400, Andrew Cagney wrote:
> >Hi,
> >
> >I would like the ability to pass the file name and line number of the
> >source corresponding to the selected stack frame to a program started
> >via the 'shell' command. I could not find any way to do this in gdb.
> >If there is a way to do this, please let me know (and disregard the rest
> >of this message.) I decided to add this functionality but I am
> >unfimiliar with the internal workings of gdb. The following is a
> >description of what I did to implement this. I'd really appreciate any
> >suggestions on better ways to implement this, error conditions I'm not
> >handling, etc.
>
> Off hand I can think of two ways to handle this:
>
> -- extend what you've proposed by including commands to explicitly
> manipulate the exported environment, vis:
> (gdb) command-to-set-shell-env VARIABLE VALUE
> (gdb) shell printenv VARIABLE
> VARIABLE=VALUE
> (gdb)
> where VALUE is something that GDB could evaluate.
Why not just use the inferior environment (set env, show env)? It's
not always appropriate, but usually it would be... and it's much more
natural, I think.
Just a thought.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-09-09 20:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-17 9:50 environment for 'shell' command Jason Kraftcheck
2002-09-09 11:45 ` Andrew Cagney
2002-09-09 13:23 ` Daniel Jacobowitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox