From: Siva Chandra <sivachandra@google.com>
To: gdb-patches@sourceware.org
Subject: [RFC] Fix for gdb.parameter('architecture') returning empty string
Date: Sat, 13 Oct 2012 23:43:00 -0000 [thread overview]
Message-ID: <CAGyQ6gzRaxiQyM71_RaX7yRiUWYGrTUpmNKpd92=MRSxShJAgQ@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1481 bytes --]
Hello,
Currently, gdb.parameter ('architecture') and gdb.parameter ('endian')
return an empty string. Attached is a patch which fixes this. I am
not very sure if this is the cleanest fix, but I could not come up
with a better one.
2012-10-13 Siva Chandra Reddy <sivachandra@google.com>
* arch-utils.c: Rename variables 'set_endian_string' and
'set_architecture_string' to 'endian_string' and
'architecture_string' respectively.
(show_endian): Use 'endian_string' instead of evaluating the
endian string value from the current architecture.
(show_architecture): Use 'architecture_string' instead of
evaluating the architecture name from the current architecture.
(set_endiani, _initialize_gdbarch_utils): Use the new
'endian_string' variable.
(selected_architecture_name, set_architecture): Use the new
'architecture_string' variable.
(set_endian_string): New convenience function to set
'endian_string'.
(on_architecture_change): Callback for the architecture change
event.
(initialize_current_architecture): Initialize
'architecture_string' and 'endian_string'. Attach the callback
on_architecture_change to the architecture change observer.
testsuite/
2012-10-13 Siva Chandra Reddy <sivachandra@google.com>
gdb.python/py-parameter.exp: Add a new test to test
gdb.parameter ('endian').
Thanks,
Siva Chandra
[-- Attachment #2: param_patch_v1.txt --]
[-- Type: text/plain, Size: 6986 bytes --]
Index: arch-utils.c
===================================================================
RCS file: /cvs/src/src/gdb/arch-utils.c,v
retrieving revision 1.204
diff -u -p -r1.204 arch-utils.c
--- arch-utils.c 8 Jun 2012 14:24:56 -0000 1.204
+++ arch-utils.c 12 Oct 2012 18:25:33 -0000
@@ -32,6 +32,7 @@
#include "target-descriptions.h"
#include "objfiles.h"
#include "language.h"
+#include "observer.h"
#include "version.h"
@@ -259,7 +260,7 @@ static const char *const endian_enum[] =
endian_auto,
NULL,
};
-static const char *set_endian_string;
+static const char *endian_string;
enum bfd_endian
selected_byte_order (void)
@@ -274,19 +275,13 @@ show_endian (struct ui_file *file, int f
const char *value)
{
if (target_byte_order_user == BFD_ENDIAN_UNKNOWN)
- if (gdbarch_byte_order (get_current_arch ()) == BFD_ENDIAN_BIG)
fprintf_unfiltered (file, _("The target endianness is set automatically "
- "(currently big endian)\n"));
- else
- fprintf_unfiltered (file, _("The target endianness is set automatically "
- "(currently little endian)\n"));
+ "(currently %s endian)\n"),
+ endian_string);
else
- if (target_byte_order_user == BFD_ENDIAN_BIG)
- fprintf_unfiltered (file,
- _("The target is assumed to be big endian\n"));
- else
fprintf_unfiltered (file,
- _("The target is assumed to be little endian\n"));
+ _("The target is assumed to be %s endian\n"),
+ endian_string);
}
static void
@@ -296,14 +291,14 @@ set_endian (char *ignore_args, int from_
gdbarch_info_init (&info);
- if (set_endian_string == endian_auto)
+ if (endian_string == endian_auto)
{
target_byte_order_user = BFD_ENDIAN_UNKNOWN;
if (! gdbarch_update_p (info))
internal_error (__FILE__, __LINE__,
_("set_endian: architecture update failed"));
}
- else if (set_endian_string == endian_little)
+ else if (endian_string == endian_little)
{
info.byte_order = BFD_ENDIAN_LITTLE;
if (! gdbarch_update_p (info))
@@ -311,7 +306,7 @@ set_endian (char *ignore_args, int from_
else
target_byte_order_user = BFD_ENDIAN_LITTLE;
}
- else if (set_endian_string == endian_big)
+ else if (endian_string == endian_big)
{
info.byte_order = BFD_ENDIAN_BIG;
if (! gdbarch_update_p (info))
@@ -416,7 +411,7 @@ enum set_arch { set_arch_auto, set_arch_
static const struct bfd_arch_info *target_architecture_user;
-static const char *set_architecture_string;
+static const char *architecture_string;
const char *
selected_architecture_name (void)
@@ -424,7 +419,7 @@ selected_architecture_name (void)
if (target_architecture_user == NULL)
return NULL;
else
- return set_architecture_string;
+ return architecture_string;
}
/* Called if the user enters ``show architecture'' without an
@@ -437,10 +432,10 @@ show_architecture (struct ui_file *file,
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);
+ architecture_string);
else
fprintf_filtered (file, _("The target architecture is assumed to be %s\n"),
- set_architecture_string);
+ architecture_string);
}
@@ -454,7 +449,7 @@ set_architecture (char *ignore_args, int
gdbarch_info_init (&info);
- if (strcmp (set_architecture_string, "auto") == 0)
+ if (strcmp (architecture_string, "auto") == 0)
{
target_architecture_user = NULL;
if (!gdbarch_update_p (info))
@@ -463,7 +458,7 @@ set_architecture (char *ignore_args, int
}
else
{
- info.bfd_arch_info = bfd_scan_arch (set_architecture_string);
+ info.bfd_arch_info = bfd_scan_arch (architecture_string);
if (info.bfd_arch_info == NULL)
internal_error (__FILE__, __LINE__,
_("set_architecture: bfd_scan_arch failed"));
@@ -471,7 +466,7 @@ set_architecture (char *ignore_args, int
target_architecture_user = info.bfd_arch_info;
else
printf_unfiltered (_("Architecture `%s' not recognized.\n"),
- set_architecture_string);
+ architecture_string);
}
show_architecture (gdb_stdout, from_tty, NULL, NULL);
}
@@ -579,6 +574,22 @@ static const bfd_target *default_bfd_vec
static int default_byte_order = BFD_ENDIAN_UNKNOWN;
+static void
+set_endian_string (struct gdbarch *arch)
+{
+ if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG)
+ endian_string = endian_big;
+ else
+ endian_string = endian_little;
+}
+
+static void
+on_architecture_change (struct gdbarch *arch)
+{
+ architecture_string = gdbarch_bfd_arch_info (arch)->printable_name;
+ set_endian_string (arch);
+}
+
void
initialize_current_architecture (void)
{
@@ -655,19 +666,26 @@ initialize_current_architecture (void)
/* Create the ``set architecture'' command appending ``auto'' to the
list of architectures. */
{
- /* Append ``auto''. */
int nr;
+ struct gdbarch *arch = get_current_arch ();
+
+ /* Append ``auto''. */
for (nr = 0; arches[nr] != NULL; nr++);
arches = xrealloc (arches, sizeof (char*) * (nr + 2));
arches[nr + 0] = "auto";
arches[nr + 1] = NULL;
+
+ architecture_string = gdbarch_bfd_arch_info (arch)->printable_name;
+ set_endian_string (arch);
+
add_setshow_enum_cmd ("architecture", class_support,
- arches, &set_architecture_string,
+ arches, &architecture_string,
_("Set architecture of target."),
_("Show architecture of target."), NULL,
set_architecture, show_architecture,
&setlist, &showlist);
add_alias_cmd ("processor", "architecture", class_support, 1, &setlist);
+ observer_attach_architecture_changed (on_architecture_change);
}
}
@@ -813,7 +831,7 @@ void
_initialize_gdbarch_utils (void)
{
add_setshow_enum_cmd ("endian", class_support,
- endian_enum, &set_endian_string,
+ endian_enum, &endian_string,
_("Set endianness of target."),
_("Show endianness of target."),
NULL, set_endian, show_endian,
Index: testsuite/gdb.python/py-parameter.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-parameter.exp,v
retrieving revision 1.6
diff -u -p -r1.6 py-parameter.exp
--- testsuite/gdb.python/py-parameter.exp 16 Jan 2012 16:21:52 -0000 1.6
+++ testsuite/gdb.python/py-parameter.exp 12 Oct 2012 18:25:33 -0000
@@ -26,6 +26,8 @@ gdb_reinitialize_dir $srcdir/$subdir
# Skip all tests if Python scripting is not enabled.
if { [skip_python_tests] } { continue }
+gdb_py_test_silent_cmd "python import sys" "Import sys" ""
+gdb_test "python print gdb.parameter ('endian') == sys.byteorder" "True"
# We use "." here instead of ":" so that this works on win32 too.
gdb_test "python print gdb.parameter ('directories')" "$srcdir/$subdir.\\\$cdir.\\\$cwd"
next reply other threads:[~2012-10-13 23:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-13 23:43 Siva Chandra [this message]
2012-10-14 7:53 ` Andreas Schwab
2012-10-14 8:37 ` Siva Chandra
2012-10-22 7:16 ` Siva Chandra
2012-11-01 20:19 ` Tom Tromey
2012-11-02 13:44 ` Siva Chandra
2012-11-02 16:59 ` Tom Tromey
2012-11-02 18:45 ` Siva Chandra
2012-11-02 19:52 ` Tom Tromey
2012-11-05 10:39 ` Phil Muldoon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAGyQ6gzRaxiQyM71_RaX7yRiUWYGrTUpmNKpd92=MRSxShJAgQ@mail.gmail.com' \
--to=sivachandra@google.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox