From: Abhijit Halder <abhijit.k.halder@gmail.com>
To: gdb-patches@sourceware.org
Subject: PATCH
Date: Sat, 09 Jul 2011 13:09:00 -0000 [thread overview]
Message-ID: <CAOhZP9x4GS=_3ShU3=0tKuqGL8K8H=iijh-gHHwRMQETOwhC-Q@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 681 bytes --]
There is no way to pass the output of a gdb command to a shell
command. For example, something similar is not permitted: "(gdb)
thread apply all bt | vim -". This kind of feature is quite helpful in
a scenario where a program under debugger has 100s of threads running
and one wants to search a particular pattern in stack-traces. I have
implemented a feature which will allow one to pass the output of any
gdb command to any shell command.
2011-07-09 Abhijit Halder <abhijit.k.halder@symantec.com>
* top.c (execute_command_to_pipe): New function.
(execute_command): Update.
* ui-file.c (gdb_modify_io): New function.
* ui-file.h (gdb_modify_io): Add prototype.
[-- Attachment #2: gdb-enhancement.patch --]
[-- Type: text/x-patch, Size: 2620 bytes --]
diff -rup src//gdb/top.c dst//gdb/top.c
--- src//gdb/top.c 2011-06-28 00:51:50.000000000 +0530
+++ dst//gdb/top.c 2011-07-09 13:11:57.480044436 +0530
@@ -48,6 +48,7 @@
#include "event-loop.h"
#include "gdbthread.h"
#include "python/python.h"
+#include "ui-file.h"
/* readline include files. */
#include "readline/readline.h"
@@ -358,6 +359,20 @@ prepare_execute_command (void)
return cleanup;
}
+
+/* Run execute_command for P and FROM_TTY. Write output in pipe,
+ do not display it to the screen. */
+
+void
+execute_command_to_pipe (char *p, int from_tty, FILE *pipe)
+{
+ FILE *file;
+
+ file = gdb_modify_io (gdb_stdout, pipe);
+ execute_command (p, from_tty);
+ pipe = gdb_modify_io (gdb_stdout, file);
+ pclose (pipe);
+}
/* Execute the line P as a command, in the current user context.
Pass FROM_TTY as second argument to the defining function. */
@@ -368,7 +383,16 @@ execute_command (char *p, int from_tty)
struct cmd_list_element *c;
enum language flang;
static int warned = 0;
- char *line;
+ char *line, *sh_cmd;
+
+ if ((sh_cmd = strchr(p,'|')) != NULL)
+ {
+ FILE *pipe;
+ *sh_cmd++ = '\0';
+ pipe = popen (sh_cmd, "w");
+ execute_command_to_pipe (p, from_tty, pipe);
+ return;
+ }
cleanup = prepare_execute_command ();
diff -rup src//gdb/ui-file.c dst//gdb/ui-file.c
--- src//gdb/ui-file.c 2011-05-14 11:14:36.000000000 +0530
+++ dst//gdb/ui-file.c 2011-07-09 13:16:50.404045208 +0530
@@ -617,6 +617,21 @@ struct ui_file *
stdio_fileopen (FILE *file)
{
return stdio_file_new (file, 0);
+
+}
+
+FILE *
+gdb_modify_io (struct ui_file *file, FILE *iostream_new)
+{
+ FILE *iostream_old;
+ struct stdio_file *stdio = ui_file_data (file);
+
+ if (stdio->magic != &stdio_file_magic)
+ internal_error (__FILE__, __LINE__,
+ _("stdio_file_flush: bad magic number"));
+ iostream_old = stdio->file;
+ stdio->file = iostream_new;
+ return iostream_old;
}
struct ui_file *
diff -rup src//gdb/ui-file.h dst//gdb/ui-file.h
--- src//gdb/ui-file.h 2011-05-13 22:58:20.000000000 +0530
+++ dst//gdb/ui-file.h 2011-07-09 13:14:21.484044803 +0530
@@ -126,6 +126,9 @@ extern struct ui_file *stdio_fileopen (F
/* Open NAME returning an STDIO based UI_FILE. */
extern struct ui_file *gdb_fopen (char *name, char *mode);
+/* Modify the file pointer of an STDIO based UI_FILE. */
+FILE *gdb_modify_io (struct ui_file *file, FILE *iostream_new);
+
/* Create a file which writes to both ONE and TWO. CLOSE_ONE
and CLOSE_TWO indicate whether the original files should be
closed when the new file is closed. */
next reply other threads:[~2011-07-09 8:30 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-09 13:09 Abhijit Halder [this message]
2011-07-09 19:06 ` PATCH oza Pawandeep
2011-07-11 12:13 ` PATCH Abhijit Halder
2011-07-11 13:42 ` PATCH Abhijit Halder
2011-07-10 7:47 ` PATCH Mike Frysinger
2011-07-11 21:10 ` PATCH Tom Tromey
2011-07-12 0:51 ` PATCH Abhijit Halder
2011-07-12 7:15 ` PATCH Abhijit Halder
2011-07-12 8:34 ` PATCH Mike Frysinger
2011-07-12 9:01 ` PATCH Abhijit Halder
2011-07-12 17:31 ` PATCH Mike Frysinger
2011-07-12 17:49 ` PATCH Matt Rice
2011-07-12 19:25 ` PATCH Mike Frysinger
2011-07-12 19:49 ` PATCH Tom Tromey
2011-07-12 20:43 ` PATCH Mike Frysinger
2011-07-13 8:45 ` PATCH Abhijit Halder
2011-07-15 14:15 ` PATCH Abhijit Halder
2011-07-15 20:49 ` PATCH Tom Tromey
2011-07-20 19:25 ` PATCH Sergio Durigan Junior
2011-07-21 11:08 ` gdb output pipelining to shell (was: Re: PATCH) Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAOhZP9x4GS=_3ShU3=0tKuqGL8K8H=iijh-gHHwRMQETOwhC-Q@mail.gmail.com' \
--to=abhijit.k.halder@gmail.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox