From patchwork Sat May 5 16:24:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 27123 Received: (qmail 57729 invoked by alias); 5 May 2018 16:25:01 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 57210 invoked by uid 89); 5 May 2018 16:25:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=nearest, callers, 1998 X-HELO: gateway31.websitewelcome.com Received: from gateway31.websitewelcome.com (HELO gateway31.websitewelcome.com) (192.185.143.36) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 05 May 2018 16:24:58 +0000 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway31.websitewelcome.com (Postfix) with ESMTP id D198A5A48 for ; Sat, 5 May 2018 11:24:56 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id EzzUf2mNZWCOCEzzUfvYQ5; Sat, 05 May 2018 11:24:56 -0500 X-Authority-Reason: nr=8 Received: from 97-122-176-117.hlrn.qwest.net ([97.122.176.117]:60596 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1fEzzU-001vWX-Id; Sat, 05 May 2018 11:24:56 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Change build_address_symbolic to return std::string Date: Sat, 5 May 2018 10:24:54 -0600 Message-Id: <20180505162454.5619-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fEzzU-001vWX-Id X-Source-Sender: 97-122-176-117.hlrn.qwest.net (bapiya.Home) [97.122.176.117]:60596 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This changes two out parameters of build_address_symbolic to be std::string, and updates the callers. This allows removing some cleanups. This patch also moves the declaration of build_address_symbolic out of defs.h. I think that many things in defs.h should be elsewhere instead. In this case, I moved the declaration to valprint.h, becuase there is no "printcmd.h" -- but perhaps it would be better to introduce that instead. Tested by the buildbot. gdb/ChangeLog 2018-05-05 Tom Tromey * valprint.h (build_address_symbolic): Declare. * printcmd.c (print_address_symbolic): Update. (build_address_symbolic): Change "name" and "filename" to std::string. * disasm.c (gdb_pretty_print_disassembler::pretty_print_insn): Update. * defs.h (build_address_symbolic): Remove declaration. --- gdb/ChangeLog | 10 ++++++++++ gdb/defs.h | 9 --------- gdb/disasm.c | 11 +++-------- gdb/printcmd.c | 29 ++++++++++------------------- gdb/valprint.h | 9 +++++++++ 5 files changed, 32 insertions(+), 36 deletions(-) diff --git a/gdb/defs.h b/gdb/defs.h index dc38a288c5..4cf83f0d44 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -327,15 +327,6 @@ extern int print_address_symbolic (struct gdbarch *, CORE_ADDR, struct ui_file *, int, const char *); -extern int build_address_symbolic (struct gdbarch *, - CORE_ADDR addr, - int do_demangle, - char **name, - int *offset, - char **filename, - int *line, - int *unmapped); - extern void print_address (struct gdbarch *, CORE_ADDR, struct ui_file *); extern const char *pc_prefix (CORE_ADDR); diff --git a/gdb/disasm.c b/gdb/disasm.c index 833341a169..2c207d10cb 100644 --- a/gdb/disasm.c +++ b/gdb/disasm.c @@ -30,6 +30,7 @@ #include "safe-ctype.h" #include #include "common/gdb_optional.h" +#include "valprint.h" /* Disassemble functions. FIXME: We should get rid of all the duplicate code in gdb that does @@ -199,8 +200,6 @@ gdb_pretty_print_disassembler::pretty_print_insn (struct ui_out *uiout, int offset; int line; int size; - char *filename = NULL; - char *name = NULL; CORE_ADDR pc; struct gdbarch *gdbarch = arch (); @@ -237,6 +236,7 @@ gdb_pretty_print_disassembler::pretty_print_insn (struct ui_out *uiout, uiout->text (pc_prefix (pc)); uiout->field_core_addr ("address", gdbarch, pc); + std::string name, filename; if (!build_address_symbolic (gdbarch, pc, 0, &name, &offset, &filename, &line, &unmapped)) { @@ -244,7 +244,7 @@ gdb_pretty_print_disassembler::pretty_print_insn (struct ui_out *uiout, the future. */ uiout->text (" <"); if ((flags & DISASSEMBLY_OMIT_FNAME) == 0) - uiout->field_string ("func-name", name); + uiout->field_string ("func-name", name.c_str ()); uiout->text ("+"); uiout->field_int ("offset", offset); uiout->text (">:\t"); @@ -252,11 +252,6 @@ gdb_pretty_print_disassembler::pretty_print_insn (struct ui_out *uiout, else uiout->text (":\t"); - if (filename != NULL) - xfree (filename); - if (name != NULL) - xfree (name); - m_insn_stb.clear (); if (flags & DISASSEMBLY_RAW_INSN) diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 4696373b2c..3b9b99ad66 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -520,47 +520,38 @@ print_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr, struct ui_file *stream, int do_demangle, const char *leadin) { - char *name = NULL; - char *filename = NULL; + std::string name, filename; int unmapped = 0; int offset = 0; int line = 0; - /* Throw away both name and filename. */ - struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name); - make_cleanup (free_current_contents, &filename); - if (build_address_symbolic (gdbarch, addr, do_demangle, &name, &offset, &filename, &line, &unmapped)) - { - do_cleanups (cleanup_chain); - return 0; - } + return 0; fputs_filtered (leadin, stream); if (unmapped) fputs_filtered ("<*", stream); else fputs_filtered ("<", stream); - fputs_filtered (name, stream); + fputs_filtered (name.c_str (), stream); if (offset != 0) fprintf_filtered (stream, "+%u", (unsigned int) offset); /* Append source filename and line number if desired. Give specific line # of this addr, if we have it; else line # of the nearest symbol. */ - if (print_symbol_filename && filename != NULL) + if (print_symbol_filename && !filename.empty ()) { if (line != -1) - fprintf_filtered (stream, " at %s:%d", filename, line); + fprintf_filtered (stream, " at %s:%d", filename.c_str (), line); else - fprintf_filtered (stream, " in %s", filename); + fprintf_filtered (stream, " in %s", filename.c_str ()); } if (unmapped) fputs_filtered ("*>", stream); else fputs_filtered (">", stream); - do_cleanups (cleanup_chain); return 1; } @@ -574,9 +565,9 @@ int build_address_symbolic (struct gdbarch *gdbarch, CORE_ADDR addr, /* IN */ int do_demangle, /* IN */ - char **name, /* OUT */ + std::string *name, /* OUT */ int *offset, /* OUT */ - char **filename, /* OUT */ + std::string *filename, /* OUT */ int *line, /* OUT */ int *unmapped) /* OUT */ { @@ -678,7 +669,7 @@ build_address_symbolic (struct gdbarch *gdbarch, *offset = addr - name_location; - *name = xstrdup (name_temp); + *name = name_temp; if (print_symbol_filename) { @@ -688,7 +679,7 @@ build_address_symbolic (struct gdbarch *gdbarch, if (sal.symtab) { - *filename = xstrdup (symtab_to_filename_for_display (sal.symtab)); + *filename = symtab_to_filename_for_display (sal.symtab); *line = sal.line; } } diff --git a/gdb/valprint.h b/gdb/valprint.h index f005c31f87..29053b5028 100644 --- a/gdb/valprint.h +++ b/gdb/valprint.h @@ -229,4 +229,13 @@ extern void print_command_parse_format (const char **expp, const char *cmdname, struct format_data *fmtp); extern void print_value (struct value *val, const struct format_data *fmtp); +extern int build_address_symbolic (struct gdbarch *, + CORE_ADDR addr, + int do_demangle, + std::string *name, + int *offset, + std::string *filename, + int *line, + int *unmapped); + #endif