• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Révisionf2f3ccb9f81255fd1b4f877600f39979c2d7ece5 (tree)
l'heure2016-03-11 07:12:30
AuteurSimon Marchi <simon.marchi@poly...>
CommiterSimon Marchi

Message de Log

Add $_as_string convenience function

This patch is a follow-up to "Add printf format specifier for printing
enumerator":

Instead of having a solution specific to the printf command, Pedro
suggested adding a general purpose function $_as_string() that would
cover this use case and more.

So, in order to print the textual label of an enum, one can use:

(gdb) printf "Visiting node of type %s\n", $_as_string(node)
Visiting node of type NODE_INTEGER

gdb/ChangeLog:

* data-directory/Makefile.in (PYTHON_FILE_LIST): Install
gdb/function/as_string.py.
* python/lib/gdb/function/as_string.py: New file.
* NEWS: Mention the new $_as_string function.

gdb/testsuite/ChangeLog:

* gdb.python/py-as-string.exp: New file.
* gdb.python/py-as-string.c: New file.

gdb/doc/ChangeLog:

* gdb.texinfo (Convenience Functions): Document $_as_string.

Change Summary

Modification

--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
1+2016-03-10 Simon Marchi <simon.marchi@polymtl.ca>
2+
3+ * data-directory/Makefile.in (PYTHON_FILE_LIST): Install
4+ gdb/function/as_string.py.
5+ * python/lib/gdb/function/as_string.py: New file.
6+ * NEWS: Mention the new $_as_string function.
7+
18 2016-03-09 Jose E. Marchesi <jose.marchesi@oracle.com>
29
310 * target.h: Fix doc string of target_can_use_hardware_watchpoint.
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,10 @@
33
44 *** Changes since GDB 7.11
55
6+* New Python-based convenience function $_as_string(val), which returns
7+ the textual representation of a value. This function is especially
8+ useful to obtain the text label of an enum value.
9+
610 * Intel MPX bound violation handling.
711
812 Segmentation faults caused by a Intel MPX boundary violation
--- a/gdb/data-directory/Makefile.in
+++ b/gdb/data-directory/Makefile.in
@@ -74,6 +74,7 @@ PYTHON_FILE_LIST = \
7474 gdb/command/prompt.py \
7575 gdb/command/explore.py \
7676 gdb/function/__init__.py \
77+ gdb/function/as_string.py \
7778 gdb/function/caller_is.py \
7879 gdb/function/strfns.py \
7980 gdb/printer/__init__.py \
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,7 @@
1+2016-03-10 Simon Marchi <simon.marchi@polymtl.ca>
2+
3+ * gdb.texinfo (Convenience Functions): Document $_as_string.
4+
15 2016-02-23 Doug Evans <dje@google.com>
26
37 * gdb.texinfo (Skipping Over Functions and Files): Document new
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -10760,6 +10760,19 @@ checks all stack frames from the immediate caller to the frame specified
1076010760 by @var{number_of_frames}, whereas @code{$_caller_matches} only checks the
1076110761 frame specified by @var{number_of_frames}.
1076210762
10763+@item $_as_string(@var{value})
10764+@findex $_as_string@r{, convenience function}
10765+Return the string representation of @var{value}.
10766+
10767+This function is useful to obtain the textual label (enumerator) of an
10768+enumeration value. For example, assuming the variable @var{node} is of
10769+an enumerated type:
10770+
10771+@smallexample
10772+(gdb) printf "Visiting node of type %s\n", $_as_string(node)
10773+Visiting node of type NODE_INTEGER
10774+@end smallexample
10775+
1076310776 @end table
1076410777
1076510778 @value{GDBN} provides the ability to list and get help on
--- /dev/null
+++ b/gdb/python/lib/gdb/function/as_string.py
@@ -0,0 +1,39 @@
1+# Copyright (C) 2016 Free Software Foundation, Inc.
2+
3+# This program is free software; you can redistribute it and/or modify
4+# it under the terms of the GNU General Public License as published by
5+# the Free Software Foundation; either version 3 of the License, or
6+# (at your option) any later version.
7+#
8+# This program is distributed in the hope that it will be useful,
9+# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+# GNU General Public License for more details.
12+#
13+# You should have received a copy of the GNU General Public License
14+# along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
16+import gdb
17+
18+
19+class _AsString(gdb.Function):
20+ """Return the string representation of a value.
21+
22+Usage:
23+ $_as_string(value)
24+
25+Arguments:
26+
27+ value: A gdb.Value.
28+
29+Returns:
30+ The string representation of the value.
31+"""
32+
33+ def __init__(self):
34+ super(_AsString, self).__init__("_as_string")
35+
36+ def invoke(self, val):
37+ return str(val)
38+
39+_AsString()
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
1+2016-03-10 Simon Marchi <simon.marchi@polymtl.ca>
2+
3+ * gdb.python/py-as-string.exp: New file.
4+ * gdb.python/py-as-string.c: New file.
5+
16 2016-03-09 Pedro Alves <palves@redhat.com>
27
38 * gdb.threads/attach-into-signal.exp: Adjust to "Program received
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-as-string.c
@@ -0,0 +1,32 @@
1+/* This testcase is part of GDB, the GNU debugger.
2+
3+ Copyright 2016 Free Software Foundation, Inc.
4+
5+ This program is free software; you can redistribute it and/or modify
6+ it under the terms of the GNU General Public License as published by
7+ the Free Software Foundation; either version 3 of the License, or
8+ (at your option) any later version.
9+
10+ This program is distributed in the hope that it will be useful,
11+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ GNU General Public License for more details.
14+
15+ You should have received a copy of the GNU General Public License
16+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
17+
18+enum EnumType {
19+ ENUM_VALUE_A,
20+ ENUM_VALUE_B,
21+ ENUM_VALUE_C,
22+ ENUM_VALUE_D,
23+};
24+
25+static enum EnumType enum_valid = ENUM_VALUE_B;
26+static enum EnumType enum_invalid = 20;
27+
28+int
29+main ()
30+{
31+ return 0;
32+}
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-as-string.exp
@@ -0,0 +1,40 @@
1+# Copyright (C) 2016 Free Software Foundation, Inc.
2+
3+# This program is free software; you can redistribute it and/or modify
4+# it under the terms of the GNU General Public License as published by
5+# the Free Software Foundation; either version 3 of the License, or
6+# (at your option) any later version.
7+#
8+# This program is distributed in the hope that it will be useful,
9+# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+# GNU General Public License for more details.
12+#
13+# You should have received a copy of the GNU General Public License
14+# along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
16+# This file is part of the GDB testsuite. It tests the convenience
17+# functions in as_string.py.
18+
19+load_lib gdb-python.exp
20+
21+standard_testfile
22+
23+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
24+ return -1
25+}
26+
27+if ![runto_main] {
28+ fail "Couldn't run to main."
29+ return 0
30+}
31+
32+if { [skip_python_tests] } { continue }
33+
34+proc test_as_string { } {
35+ gdb_test "p \$_as_string(2)" "\"2\""
36+ gdb_test "p \$_as_string(enum_valid)" "\"ENUM_VALUE_B\""
37+ gdb_test "p \$_as_string(enum_invalid)" "\"20\""
38+}
39+
40+test_as_string