Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests, warnings and a memory leak #3

Open
wants to merge 9 commits into
base: gdb-8.1-suse-target
Choose a base branch
from
4 changes: 1 addition & 3 deletions gdb/python/py-minsymbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ static const struct objfile_data *msympy_objfile_data_key;
static PyObject *
msympy_str (PyObject *self)
{
PyObject *result;
struct minimal_symbol *minsym = NULL;

MSYMPY_REQUIRE_VALID (self, minsym);
Expand Down Expand Up @@ -334,7 +333,6 @@ gdb_PyUnicode_AsUTF8(PyObject *obj)
PyObject *
gdbpy_lookup_minimal_symbol (PyObject *self, PyObject *args, PyObject *kw)
{
int domain = VAR_DOMAIN;
const char *name, *sfile = NULL;
struct objfile *objfile = NULL;
static const char *keywords[] = { "name", "sfile", "objfile", NULL };
Expand Down Expand Up @@ -402,7 +400,7 @@ del_objfile_msymbols (struct objfile *objfile, void *datum)
obj->next = NULL;
obj->prev = NULL;

obj = obj->next;
obj = next;
}
}

Expand Down
22 changes: 0 additions & 22 deletions gdb/testsuite/gdb.python/Makefile.in

This file was deleted.

38 changes: 38 additions & 0 deletions gdb/testsuite/gdb.python/py-minsymbol.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* This testcase is part of GDB, the GNU debugger.

Copyright 2018 Free Software Foundation, Inc.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */

/* So we have a data section */
const char foo[] = "somestring";

asm("\
.section .text\n\
.global text_msym\n\
text_msym:\n\
.byte 0\n\
.section .data\n\
.globl data_msym\n\
data_msym:\n\
.asciz \"minsym text\"\n\
data_msym2:\n\
.asciz \"minsym2 text\"\n\
");

int
main (void)
{
return 0;
}
35 changes: 19 additions & 16 deletions gdb/testsuite/gdb.python/py-minsymbol.exp
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,34 @@ if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} {
if { [skip_python_tests] } { continue }

# Test looking up missing value
gdb_test "python print gdb.lookup_minimal_symbol('xyz')" "None" "lookup missing symbol"
gdb_test "python print (gdb.lookup_minimal_symbol('xyz'))" "None" "lookup missing symbol"

# Test looking up a minimal symbol of text type
gdb_test "print text_msym" " = \{<text variable, no debug info>\} 0x\[0-9a-f\]* <text_msym>" "locate text_msym with print"
gdb_py_test_silent_cmd "python x = gdb.lookup_minimal_symbol('text_msym')" "Lookup text_msym" 1
gdb_test "python print x" "text_msym" "lookup text min sym"
gdb_test "python print x.name" "text_msym" "get text minsym name"
gdb_test "python print x.linkage_name" "text_msym" "get text minsym linkage_name"
gdb_test "python print (x)" "text_msym" "lookup text min sym"
gdb_test "python print (x.name)" "text_msym" "get text minsym name"
gdb_test "python print (x.linkage_name)" "text_msym" "get text minsym linkage_name"
# Using asm() ends up inventing a compiler-dependent filename
gdb_test "python print x.filename" ".*" "get text minsym filename"
gdb_test "python print x.print_name" "text_msym" "get text minsym print_name"
gdb_test "python print x.section" ".text" "get text minsym section"
gdb_test "python print x.value()" "0x\[0-9a-f\]*.*" "get text minsym value"
gdb_test "python print x.value().type" "void \\(\\*\\)\\(\\)" "get text minsym value type"
gdb_test "python print (x.filename)" ".*" "get text minsym filename"
gdb_test "python print (x.print_name)" "text_msym" "get text minsym print_name"
gdb_test "python print (x.section)" ".text" "get text minsym section"
gdb_test "python print (x.value())" "0x\[0-9a-f\]*.*" "get text minsym value"
gdb_test "python print (x.value().type)" "void \\(\\*\\)\\(\\)" "get text minsym value type"

# Test looking up a minimal symbol of data type
gdb_test "print data_msym" " = \[0-9\]*" "locate data_msym with print"
gdb_test "print (void *)data_msym" "0x\[0-9a-f\]*.*" "locate data_msym with print"
gdb_py_test_silent_cmd "python x = gdb.lookup_minimal_symbol('data_msym')" "Lookup data_msym" 1
gdb_test "python print x.name" "data_msym" "get data minsym name"
gdb_test "python print x.linkage_name" "data_msym" "get data minsym linkage_name"
gdb_test "python print (x.name)" "data_msym" "get data minsym name"
gdb_test "python print (x.linkage_name)" "data_msym" "get data minsym linkage_name"
# Using asm() ends up inventing a compiler-dependent filename
gdb_test "python print x.filename" ".*" "get data minsym filename"
gdb_test "python print x.print_name" "data_msym" "get data minsym print_name"
gdb_test "python print x.section" ".data" "get data minsym section"
gdb_test "python print x.value()" "0x\[0-9a-f\]*.*" "get data minsym value"
gdb_test "python print (x.filename)" ".*" "get data minsym filename"
gdb_test "python print (x.print_name)" "data_msym" "get data minsym print_name"
gdb_test "python print (x.section)" ".data" "get data minsym section"
gdb_test "python print (x.value())" "0x\[0-9a-f\]*.*" "get data minsym value"

gdb_test "python print(gdb.lookup_minimal_symbol('data_msym2', 'foobar.c'))" "None" "Lookup data_msym2 in foobar.c src"
gdb_test "python print(gdb.lookup_minimal_symbol('data_msym2', 'py-minsymbol.c'))" "data_msym2" "Lookup data_msym2 in py-minsymbol.c src"

gdb_unload
gdb_test "python print (x.is_valid())" "False" "Test symbol non-validity"
Expand Down
4 changes: 2 additions & 2 deletions gdb/testsuite/gdb.python/py-register.exp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ gdb_py_test_silent_cmd "python regs = gdb.selected_thread().registers" "Keep a

# Hopefully an architecture-independent way of finding a GPR to test; Reg #0
gdb_py_test_silent_cmd "python gpr0 = sorted(regs.values(), key=lambda x: x.regnum)\[0\]" "saving the name of GPR#0" 1
gdb_test "python print gpr0" "<gdb.Register object at.*" "Test to get a register"
gdb_test "python print (gpr0)" "<gdb.Register object at.*" "Test to get a register"
gdb_py_test_silent_cmd "python gpr0.value = 1" "Test assignment to GPR" 1
gdb_test_multiple "python gpr0.value = \"oh hai\"" "Test assignment to GPR of invalid type" {
-re "Traceback.*TypeError:.*$gdb_prompt $" {
Expand All @@ -52,7 +52,7 @@ gdb_test_multiple "python regs\[\'foo\'\] = 0" "Testing that register dict is st
pass "1"
}
}
gdb_test_multiple "python print regs\[\'foo\'\]" "Testing that register dict is static (reading)" {
gdb_test_multiple "python print (regs\[\'foo\'\])" "Testing that register dict is static (reading)" {
-re "Traceback.*KeyError:.*$gdb_prompt $" {
pass "1"
}
Expand Down
4 changes: 2 additions & 2 deletions gdb/testsuite/gdb.python/py-symbol.exp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ gdb_test "python print (gdb.lookup_global_symbol('qq').needs_frame)" \

# Test looking up a static symbol that doesn't require a frame
gdb_test_no_output "python staticfunc = gdb.lookup_symbol(\"staticfunc\", None)" ""
gdb_test "python print staticfunc\[0\]" "staticfunc" "Test staticfunc lookup"
gdb_test "python print (staticfunc\[0\])" "staticfunc" "Test staticfunc lookup"

gdb_test_no_output "python staticfunc = gdb.lookup_symbol(\"does_not_exist\", None)" ""
gdb_test "python print staticfunc\[0\]" "None" "Test missing symbol lookup"
gdb_test "python print (staticfunc\[0\])" "None" "Test missing symbol lookup"



Expand Down