From patchwork Tue Aug 4 15:40:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 7998 Received: (qmail 16335 invoked by alias); 4 Aug 2015 15:40:58 -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 16138 invoked by uid 89); 4 Aug 2015 15:40:57 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=0.1 required=5.0 tests=AWL, BAYES_50, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-wi0-f179.google.com Received: from mail-wi0-f179.google.com (HELO mail-wi0-f179.google.com) (209.85.212.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 04 Aug 2015 15:40:52 +0000 Received: by wibud3 with SMTP id ud3so29421315wib.0 for ; Tue, 04 Aug 2015 08:40:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=kJVOPz/KXDTX+iLMI0F7gNaUJI5zRL2VwU2F8AdqCUk=; b=IoylgniVTd9knCvJGKwhRpGvUKp2Ynfs2xdQTV2TPLGLVdzH2fY1MMUMJPwU+FCLxW JqwrYmVlvxaN6nE3ktE93C5VLfyqqtXKsLiJn+F/X+3OqsGzipe5O68aUA7iwfQMt/ud 167YvW+H1y/FPIHVDLWkIvetUaLKYVfLLEI7sq+Jj0wYdJF6rgMJeahpcMQ4L4EoEZgU 2GDGHOCJTYlZyxgLABd3nzMS83L7HQqkV8bmNOscZS+D7Od9T5Of/dbNHSf0U3dpVaxB JxZegCf9cUWr9Y96rlbGrx2RLq0s3/qDJlTyXiGjaUPEHILEWsIo6J2PKG+PCKYzPnZz 6gww== X-Gm-Message-State: ALoCoQlBarsiJcwyjgVzXzqqMHPMMjnrARoQx4iNrD5YSaFTB/RpfpHSpkFaAFo7s3WGRTUapwJA X-Received: by 10.180.219.41 with SMTP id pl9mr9273534wic.30.1438702849427; Tue, 04 Aug 2015 08:40:49 -0700 (PDT) Received: from localhost (cust64-dsl91-135-5.idnet.net. [91.135.5.64]) by smtp.gmail.com with ESMTPSA id pn6sm2425186wjb.36.2015.08.04.08.40.48 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Aug 2015 08:40:48 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 2/2] gdb: Move get_frame_language from stack.c to frame.c. Date: Tue, 4 Aug 2015 16:40:42 +0100 Message-Id: <568a4c1273713e14f691586c2d32bdbd3be610a1.1438699523.git.andrew.burgess@embecosm.com> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes The get_frame_language feels like it would be more at home in frame.c rather than in stack.c, while the declaration, that is currently in language.h can be moved into frame.h to match. A couple of new includes are added, but otherwise no substantial change here. gdb/ChangeLog: * stack.c (get_frame_language): Moved ... * frame.c (get_frame_language): ... to here. * language.h (get_frame_language): Declaration moved ... * frame.h (get_frame_language): ... to here. (enum language): Add declaration. * language.c: Add frame.h include. * top.c: Add frame.h include. --- gdb/ChangeLog | 10 ++++++++++ gdb/frame.c | 42 ++++++++++++++++++++++++++++++++++++++++++ gdb/frame.h | 6 ++++++ gdb/language.c | 1 + gdb/language.h | 2 -- gdb/stack.c | 42 ------------------------------------------ gdb/top.c | 1 + 7 files changed, 60 insertions(+), 44 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 223d2e5..f383dd7 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,15 @@ 2015-08-04 Andrew Burgess + * stack.c (get_frame_language): Moved ... + * frame.c (get_frame_language): ... to here. + * language.h (get_frame_language): Declaration moved ... + * frame.h (get_frame_language): ... to here. + (enum language): Add declaration. + * language.c: Add frame.h include. + * top.c: Add frame.h include. + +2015-08-04 Andrew Burgess + * language.c (show_language_command): Find selected frame before asking for the language of that frame. (set_language_command): Likewise. diff --git a/gdb/frame.c b/gdb/frame.c index da5bfb9..f05f739 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -2571,6 +2571,48 @@ frame_unwind_caller_arch (struct frame_info *next_frame) return frame_unwind_arch (skip_artificial_frames (next_frame)); } +/* Gets the language of FRAME. */ + +enum language +get_frame_language (struct frame_info *frame) +{ + CORE_ADDR pc = 0; + int pc_p = 0; + + gdb_assert (frame!= NULL); + + /* We determine the current frame language by looking up its + associated symtab. To retrieve this symtab, we use the frame + PC. However we cannot use the frame PC as is, because it + usually points to the instruction following the "call", which + is sometimes the first instruction of another function. So + we rely on get_frame_address_in_block(), it provides us with + a PC that is guaranteed to be inside the frame's code + block. */ + + TRY + { + pc = get_frame_address_in_block (frame); + pc_p = 1; + } + CATCH (ex, RETURN_MASK_ERROR) + { + if (ex.error != NOT_AVAILABLE_ERROR) + throw_exception (ex); + } + END_CATCH + + if (pc_p) + { + struct compunit_symtab *cust = find_pc_compunit_symtab (pc); + + if (cust != NULL) + return compunit_language (cust); + } + + return language_unknown; +} + /* Stack pointer methods. */ CORE_ADDR diff --git a/gdb/frame.h b/gdb/frame.h index be64c57..6c39b86 100644 --- a/gdb/frame.h +++ b/gdb/frame.h @@ -814,4 +814,10 @@ extern struct frame_info *create_new_frame (CORE_ADDR base, CORE_ADDR pc); extern int frame_unwinder_is (struct frame_info *fi, const struct frame_unwind *unwinder); +/* Return the language of FRAME. */ + +enum language; +extern enum language get_frame_language (struct frame_info *frame); + + #endif /* !defined (FRAME_H) */ diff --git a/gdb/language.c b/gdb/language.c index 989a8da..b130f50 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -43,6 +43,7 @@ #include "demangle.h" #include "symfile.h" #include "cp-support.h" +#include "frame.h" extern void _initialize_language (void); diff --git a/gdb/language.h b/gdb/language.h index 8782ef0..2265afc 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -544,8 +544,6 @@ extern const char *language_str (enum language); extern void add_language (const struct language_defn *); -extern enum language get_frame_language (struct frame_info *frame); /* In stack.c */ - /* Check for a language-specific trampoline. */ extern CORE_ADDR skip_language_trampoline (struct frame_info *, CORE_ADDR pc); diff --git a/gdb/stack.c b/gdb/stack.c index 31a723d..ae53ec8 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -2559,48 +2559,6 @@ func_command (char *arg, int from_tty) else if (frame != get_selected_frame (NULL)) select_and_print_frame (frame); } - -/* Gets the language of FRAME. */ - -enum language -get_frame_language (struct frame_info *frame) -{ - CORE_ADDR pc = 0; - int pc_p = 0; - - gdb_assert (frame!= NULL); - - /* We determine the current frame language by looking up its - associated symtab. To retrieve this symtab, we use the frame - PC. However we cannot use the frame PC as is, because it - usually points to the instruction following the "call", which - is sometimes the first instruction of another function. So - we rely on get_frame_address_in_block(), it provides us with - a PC that is guaranteed to be inside the frame's code - block. */ - - TRY - { - pc = get_frame_address_in_block (frame); - pc_p = 1; - } - CATCH (ex, RETURN_MASK_ERROR) - { - if (ex.error != NOT_AVAILABLE_ERROR) - throw_exception (ex); - } - END_CATCH - - if (pc_p) - { - struct compunit_symtab *cust = find_pc_compunit_symtab (pc); - - if (cust != NULL) - return compunit_language (cust); - } - - return language_unknown; -} /* Provide a prototype to silence -Wmissing-prototypes. */ diff --git a/gdb/top.c b/gdb/top.c index d17891e..364ca88 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -49,6 +49,7 @@ #include "observer.h" #include "maint.h" #include "filenames.h" +#include "frame.h" /* readline include files. */ #include "readline/readline.h"