From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 70516 invoked by alias); 26 Jul 2016 08:09:23 -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 70435 invoked by uid 89); 26 Jul 2016 08:09:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=paramjot@gmail.com, paramjotgmailcom, 2016-07-26, ideal X-HELO: mail-wm0-f53.google.com Received: from mail-wm0-f53.google.com (HELO mail-wm0-f53.google.com) (74.125.82.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 26 Jul 2016 08:09:12 +0000 Received: by mail-wm0-f53.google.com with SMTP id q128so162609171wma.1 for ; Tue, 26 Jul 2016 01:09:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Y+D5AV6QtCZIHsyVXGtv80jLGYoJseLRorWwoUf12Ok=; b=HvLVnJVZ/Q96bL65viOIZNywsv0qpOD9CIW8hyLbGQhnV3nmSj7wtewOkKUq7F5sIc PiOZriFuKoD0SEf2ej9Ay4uYn1927IGg4Ed0bRQY5+GX7BoEdnC4xxeyS4/N3kd09UQW BQ2vsywt+8K/MdA3HqR/R/Ol+rPHpf7otLlCtpEUmgOo/Wg67mJdCKPJpOBveLBrbB0w oz2tuZztXWx+bxvUhQtXAvw0qTqYkK9qMUFayzLJTaPMazbJ3CRsyJm3qSzrLFm5vq5C 3oNgN9N7IgBl0hA2V38VarxgUJ7cwpvUyiPTvMAhLC6l/j3t+p4lg2Km07fgL6i0XHtl Po8g== X-Gm-Message-State: AEkooutRJudjZ1gDF1KjEA6lkGUyuBdQVy1510rkT2PvextKe4G6yg7RtEFrDkLTh+hk9w== X-Received: by 10.194.77.97 with SMTP id r1mr20627910wjw.83.1469520549402; Tue, 26 Jul 2016 01:09:09 -0700 (PDT) Received: from localhost (host86-165-30-37.range86-165.btcentralplus.com. [86.165.30.37]) by smtp.gmail.com with ESMTPSA id a21sm276686wma.10.2016.07.26.01.09.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jul 2016 01:09:08 -0700 (PDT) Date: Tue, 26 Jul 2016 08:09:00 -0000 From: Andrew Burgess To: Paramjot Oberoi Cc: dwk , gdb@sourceware.org Subject: Re: How to Read Program Architecture from GDB/MI? Message-ID: <20160726080900.GE4517@embecosm.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] User-Agent: Mutt/1.6.1 (2016-04-27) X-IsSubscribed: yes X-SW-Source: 2016-07/txt/msg00027.txt.bz2 * Paramjot Oberoi [2016-07-26 02:27:31 -0400]: > 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 > { > ... > ... > } As you point out I don't think there's a quick fix to your problem, and the comment in 'do_show_command' acknowledges that this area is broken when it comes to MI. As a quick fix how about the patch below. It's not ideal, but it might be enough for you. The basic idea is to wrap the MI return from -gdb-show into a tuple, then add an extra field 'message', which contains the raw output of a CLI 'show' command. [ I think that long term we'd probably switch to a tuple anyway, when we correctly handle things like a variable being 'auto' we'd probably want a reply that looked something like: {value="auto", current="i386"}, so switching to a tuple is probably the way to go. ] For now however, the display of value is not fixed, so the 'auto' value does not get displayed at all, but you do always get the message string, the default reply now looks like this: (gdb) interpreter-exec mi "-gdb-show architecture" ^done,{message="The target architecture is set automatically (currently i386)\n"} You would then have to parse the message string yourself. Hope this helps, Andrew ---- diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c index eb17158..f7597cf 100644 --- a/gdb/cli/cli-setshow.c +++ b/gdb/cli/cli-setshow.c @@ -650,7 +650,23 @@ do_show_command (const char *arg, int from_tty, struct cmd_list_element *c) MI and CLI specific versions. */ if (ui_out_is_mi_like_p (uiout)) - ui_out_field_stream (uiout, "value", stb); + { + struct ui_file *msg_file; + char *value; + + make_cleanup_ui_out_tuple_begin_end (uiout, NULL); + ui_out_field_stream (uiout, "value", stb); + + value = ui_file_xstrdup (stb, NULL); + make_cleanup (xfree, value); + msg_file = mem_fileopen (); + if (c->show_value_func != NULL) + c->show_value_func (msg_file, from_tty, c, value); + else + deprecated_show_value_hack (msg_file, from_tty, c, value); + + ui_out_field_stream (uiout, "message", msg_file); + } else { char *value = ui_file_xstrdup (stb, NULL);