From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 63291 invoked by alias); 26 Jul 2016 06:27:36 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 63276 invoked by uid 89); 26 Jul 2016 06:27:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.6 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=paramjot@gmail.com, paramjotgmailcom, U*dwks42, sk:dwks42@ X-HELO: mail-yw0-f171.google.com Received: from mail-yw0-f171.google.com (HELO mail-yw0-f171.google.com) (209.85.161.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 26 Jul 2016 06:27:33 +0000 Received: by mail-yw0-f171.google.com with SMTP id z8so164586698ywa.1 for ; Mon, 25 Jul 2016 23:27:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=Gls54uqS3l4T/zVsD1zZqQZll0ArUW1SpJTOQduqg9s=; b=Pb01qCugv71rF4AkHE2uhOlbQj/LmB8jSW2Lt1ku8zFtwbC+zYIdvpsPO6cnxQHAS5 WIoQgIdIbVobrVAz6zrunNukv+UcIppwtrZ9anitcEtlytxE2Dt2LdFW1TEsOfkdFRrR 16VJz4SQFpPkXCrcJWq/6Gq8iP0M4loXIlPq6LdvBJU8AnQEstDCmEt8ajFzpcYfk55h Wh/RYwoJgc0bmwvhug9qoOQZ0jM+puDRkb4bvQl1VtOiIr04cpn/apN1R2zRb/23Kwe2 ejvL8iD60Zg1awi+YeqSROKfZgwAHZZxg3lxzKBCQ8/eF8t7zq1X/erf0Z4ImIQ7K/Xu mTYw== X-Gm-Message-State: AEkoouuETOiXFSgYInP5TlDjQcYBWFFiPDtR6gUBBn3LzzbJatgkvXcAPB/Ows7GXkdoaLdzF1X+HNcUA2/J4w== X-Received: by 10.31.74.199 with SMTP id x190mr9841932vka.42.1469514451573; Mon, 25 Jul 2016 23:27:31 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.153.4 with HTTP; Mon, 25 Jul 2016 23:27:31 -0700 (PDT) In-Reply-To: References: From: Paramjot Oberoi Date: Tue, 26 Jul 2016 06:27:00 -0000 Message-ID: Subject: Re: How to Read Program Architecture from GDB/MI? To: dwk Cc: gdb@sourceware.org Content-Type: text/plain; charset=UTF-8 X-SW-Source: 2016-07/txt/msg00026.txt.bz2 Thank you for the quick response, it got me down the right track. Unfortunately simply commenting out that if() won't work for me as the output will no longer have the GDB/MI request IDs. It would be the same as if I did "interpreter-exec mi "show architecture." I believe the correct fix will require some proper planning. I've spent a few hours looking at GDB's source code and I can't think of a clean way to implement it. The core issue is the output from "show architecture" and "interpreter-exec mi "-gdb-show architecture"" do not match in the case that the architecture is not set or is set to auto. If you manually set the architecture ("set architecture i386") the GDB/MI output is correct. As you mentioned the c->show_value_func (show_architecture) only gets called for the console output case, and not for the GDB/MI. It is the source of the difference. Console output: (gdb) show architecture The target architecture is set automatically (currently i386) ---> set_architecture_string is NULL, but output correctly says the target architecture is auto, and prints out the current architecture (gdb) set architecture auto The target architecture is set automatically (currently i386) (gdb) show architecture The target architecture is set automatically (currently i386) ---> set_architecture_string is "auto", and prints out the current architecture GDB/MI output: (gdb) interpreter-exec mi "-gdb-show architecture" ^done ---> set_architecture_string is NULL so nothing is output, does not print out the current architecture (gdb) set architecture auto The target architecture is set automatically (currently i386) (gdb) interpreter-exec mi "-gdb-show architecture" ^done,value="auto" ---> set_architecture_string is "auto", does not print out the current architecture c->show_value_func (show_architecture) is what handles the special logic for having "auto" or uninitialized architectures: static void show_architecture (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) { if (target_architecture_user == NULL) fprintf_filtered (file, _("The target architecture is set " "automatically (currently %s)\n"), gdbarch_bfd_arch_info (get_current_arch ())->printable_name); else fprintf_filtered (file, _("The target architecture is assumed to be %s\n"), set_architecture_string); } There is no such equivalent callback for the GDB/MI case. I can't think of a way to do this that wouldn't be hackish. One thought was to modify the if() else to specifically look for this case: if (ui_out_is_mi_like_p (uiout)) { if(c->show_value_func == show_architecture) { // reimplement the logic of show_architecture() here, but for MI // we would need to wipe the existing stb because it might already have the word "auto" in there } ui_out_field_stream (uiout, "value", stb); } else { ... ... } Again this doesn't seem like a good way to do it. Please let me know what your thoughts are. Thanks in advance. On Mon, Jul 25, 2016 at 1:27 PM, dwk wrote: > This is a bug in gdb/cli/cli-setshow.c. The current code reads > > 647 /* FIXME: cagney/2005-02-10: Need to split this in half: code to > 648 convert the value into a string (esentially the above); and > 649 code to print the value out. For the latter there should be > 650 MI and CLI specific versions. */ > 651 > 652 if (ui_out_is_mi_like_p (uiout)) > 653 ui_out_field_stream (uiout, "value", stb); > 654 else > 655 { > 656 char *value = ui_file_xstrdup (stb, NULL); > 657 > 658 make_cleanup (xfree, value); > 659 if (c->show_value_func != NULL) > 660 c->show_value_func (gdb_stdout, from_tty, c, value); > 661 else > 662 deprecated_show_value_hack (gdb_stdout, from_tty, c, value); > 663 } > > The if statement is a special case for GDB/MI. It seems to prepare to > generate a value but then never write anything. My guess is that this > code was supposed to generate a nicely parsable version of the string. In > the case of "-gdb-show architecture", there is a c->show_value_func > (show_architecture) to call which prints "unfriendly" output. I tried > playing with different code here but the simplest fix seems to be to > disable the if statement entirely (add 0&& to its test). Then your > "show architecture" command works correctly. > > (gdb) interpreter-exec mi "-gdb-show architecture" > ~"The target architecture is set automatically (currently i386)\n" > ^done > (gdb) > > I don't know what cagney was worrying about when this split occurred, > but given that it was in 2005 it may no longer be an issue. Perhaps > try disabling the if statement as I suggested and see if other problems > crop up. > > diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c > index eb17158..8d9b691 100644 > --- a/gdb/cli/cli-setshow.c > +++ b/gdb/cli/cli-setshow.c > @@ -649,7 +649,7 @@ do_show_command (const char *arg, int from_tty, > struct cmd_list_element *c) > code to print the value out. For the latter there should be > MI and CLI specific versions. */ > > - if (ui_out_is_mi_like_p (uiout)) > + if (0 && ui_out_is_mi_like_p (uiout)) > ui_out_field_stream (uiout, "value", stb); > else > { > > > Cheers. > > ~~ dwk > > On Mon, Jul 25, 2016 at 1:30 AM, Paramjot Oberoi wrote: >> Hi all, >> >> I am attempting to get the CPU architecture of the currently debugged >> program via a GDB/MI command. I'm not sure what's I'm doing wrong: >> >> Console interpreter looks good: >> (gdb) show architecture >> The target architecture is set automatically (currently i386) >> >> MI interpreter succeeds without any data: >> (gdb) interpreter-exec mi "-gdb-show architecture" >> ^done >> >> If I set the arch to auto, then query with MI I get "auto" back...: >> (gdb) set arch auto >> The target architecture is set automatically (currently i386) >> (gdb) interpreter-exec mi "-gdb-show architecture" >> ^done,value="auto" >> >> Any advice on how I can query the architecture in GDB/MI mode? Thanks >> in advance, I appreciate it.