+2015-08-07 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * language.c (show_language_command): Find selected frame before
+ asking for the language of that frame.
+ (set_language_command): Likewise.
+ * language.h (get_frame_language): Add frame parameter.
+ * stack.c (get_frame_language): Add frame parameter, assert
+ parameter is not NULL, update comment and reindent.
+ * top.c (check_frame_language_change): Pass the selected frame
+ into get_frame_language.
+
2015-08-07 Markus Metzger <markus.t.metzger@intel.com>
* btrace.c (btrace_compute_ftrace_bts): Clear insn flags.
show_language_command (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
- enum language flang; /* The language of the current frame. */
+ enum language flang; /* The language of the frame. */
if (language_mode == language_mode_auto)
fprintf_filtered (gdb_stdout,
_("The current source language is \"%s\".\n"),
current_language->la_name);
- flang = get_frame_language ();
- if (flang != language_unknown &&
- language_mode == language_mode_manual &&
- current_language->la_language != flang)
- printf_filtered ("%s\n", lang_frame_mismatch_warn);
+ if (has_stack_frames ())
+ {
+ struct frame_info *frame;
+
+ frame = get_selected_frame (NULL);
+ flang = get_frame_language (frame);
+ if (flang != language_unknown
+ && language_mode == language_mode_manual
+ && current_language->la_language != flang)
+ printf_filtered ("%s\n", lang_frame_mismatch_warn);
+ }
}
/* Set command. Change the current working language. */
set_language_command (char *ignore, int from_tty, struct cmd_list_element *c)
{
int i;
- enum language flang;
+ enum language flang = language_unknown;
/* Search the list of languages for a match. */
for (i = 0; i < languages_size; i++)
/* Enter auto mode. Set to the current frame's language, if
known, or fallback to the initial language. */
language_mode = language_mode_auto;
- flang = get_frame_language ();
+ TRY
+ {
+ struct frame_info *frame;
+
+ frame = get_selected_frame (NULL);
+ flang = get_frame_language (frame);
+ }
+ CATCH (ex, RETURN_MASK_ERROR)
+ {
+ flang = language_unknown;
+ }
+ END_CATCH
+
if (flang != language_unknown)
set_language (flang);
else
extern void add_language (const struct language_defn *);
-extern enum language get_frame_language (void); /* In stack.c */
+extern enum language get_frame_language (struct frame_info *frame); /* In stack.c */
/* Check for a language-specific trampoline. */
select_and_print_frame (frame);
}
-/* Gets the language of the current frame. */
+/* Gets the language of FRAME. */
enum language
-get_frame_language (void)
+get_frame_language (struct frame_info *frame)
{
- struct frame_info *frame = deprecated_safe_get_selected_frame ();
+ CORE_ADDR pc = 0;
+ int pc_p = 0;
- if (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. */
+ /* 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
+ 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 (pc_p)
+ {
+ struct compunit_symtab *cust = find_pc_compunit_symtab (pc);
- if (cust != NULL)
- return compunit_language (cust);
- }
+ if (cust != NULL)
+ return compunit_language (cust);
}
return language_unknown;
check_frame_language_change (void)
{
static int warned = 0;
+ struct frame_info *frame;
/* First make sure that a new frame has been selected, in case the
command or the hooks changed the program state. */
- deprecated_safe_get_selected_frame ();
+ frame = deprecated_safe_get_selected_frame ();
if (current_language != expected_language)
{
if (language_mode == language_mode_auto && info_verbose)
{
enum language flang;
- flang = get_frame_language ();
+ flang = get_frame_language (frame);
if (!warned
&& flang != language_unknown
&& flang != current_language->la_language)