2002-06-11 22:27:50 +02:00
|
|
|
# Test macro scoping.
|
2011-01-01 16:34:07 +01:00
|
|
|
# Copyright 2002, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
2002-06-11 22:27:50 +02:00
|
|
|
|
|
|
|
# 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
|
2007-08-23 20:14:19 +02:00
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
2002-06-11 22:27:50 +02:00
|
|
|
# (at your option) any later version.
|
2007-08-23 20:14:19 +02:00
|
|
|
#
|
2002-06-11 22:27:50 +02:00
|
|
|
# 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.
|
2007-08-23 20:14:19 +02:00
|
|
|
#
|
2002-06-11 22:27:50 +02:00
|
|
|
# You should have received a copy of the GNU General Public License
|
2007-08-23 20:14:19 +02:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2002-06-11 22:27:50 +02:00
|
|
|
|
|
|
|
if $tracelevel then {
|
|
|
|
strace $tracelevel
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-04 00:30:51 +02:00
|
|
|
set srcfile macscp1.c
|
2002-06-11 22:27:50 +02:00
|
|
|
set testfile "macscp"
|
2009-02-18 23:24:37 +01:00
|
|
|
set objfile ${objdir}/${subdir}/${testfile}.o
|
2002-06-11 22:27:50 +02:00
|
|
|
set binfile ${objdir}/${subdir}/${testfile}
|
|
|
|
|
2009-04-29 09:51:33 +02:00
|
|
|
set options { debug additional_flags=-DFROM_COMMANDLINE=ARG}
|
2008-04-25 23:47:11 +02:00
|
|
|
|
|
|
|
get_compiler_info ${binfile}
|
|
|
|
if [test_compiler_info gcc*] {
|
|
|
|
lappend options additional_flags=-g3
|
|
|
|
}
|
|
|
|
|
2008-12-04 16:35:43 +01:00
|
|
|
# Generate the intermediate object file. This is required by Darwin to
|
|
|
|
# have access to the .debug_macinfo section.
|
|
|
|
if {[gdb_compile "${srcdir}/${subdir}/macscp1.c" "${objfile}" \
|
|
|
|
object $options] != ""
|
|
|
|
|| [gdb_compile "${objfile}" "${binfile}" executable $options] != "" } {
|
2006-08-10 07:27:22 +02:00
|
|
|
untested macscp.exp
|
|
|
|
return -1
|
2002-06-11 22:27:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gdb_exit
|
|
|
|
gdb_start
|
|
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
|
|
|
gdb_load ${binfile}
|
|
|
|
|
|
|
|
|
|
|
|
# Ask GDB to show the current definition of MACRO, and return a list
|
|
|
|
# describing the result.
|
|
|
|
#
|
|
|
|
# The return value has the form {FILE1 FILE2 ... DEF}, which means
|
|
|
|
# that MACRO has the definition `DEF', and was defined in `FILE1',
|
|
|
|
# which was included from `FILE2', included from ... .
|
|
|
|
#
|
|
|
|
# If GDB says that MACRO has no definition, return the string `undefined'.
|
|
|
|
#
|
|
|
|
# If GDB complains that it doesn't have any information about
|
|
|
|
# preprocessor macro definitions, return the string `no-macro-info'.
|
|
|
|
#
|
|
|
|
# If expect times out waiting for GDB, we return the string `timeout'.
|
|
|
|
#
|
|
|
|
# If GDB's output doesn't otherwise match what we're expecting, we
|
|
|
|
# return the empty string.
|
|
|
|
|
|
|
|
proc info_macro {macro} {
|
|
|
|
global gdb_prompt
|
|
|
|
|
|
|
|
set filepat {macscp[0-9]+\.[ch]}
|
|
|
|
set definition {}
|
|
|
|
set location {}
|
|
|
|
|
2009-04-29 09:51:33 +02:00
|
|
|
# Line number zero is set for macros defined from the compiler command-line.
|
|
|
|
# Such macros are not being tested by this function.
|
|
|
|
set nonzero {[1-9][0-9]*}
|
|
|
|
|
2002-06-11 22:27:50 +02:00
|
|
|
send_gdb "info macro ${macro}\n"
|
|
|
|
|
|
|
|
set debug_me 0
|
|
|
|
|
|
|
|
if {$debug_me} {exp_internal 1}
|
|
|
|
gdb_expect {
|
2009-04-29 09:51:33 +02:00
|
|
|
-re "Defined at \[^\r\n\]*(${filepat}):${nonzero}\[\r\n\]" {
|
2002-06-11 22:27:50 +02:00
|
|
|
# `location' and `definition' should be empty when we see
|
|
|
|
# this message.
|
|
|
|
if {[llength $location] == 0 && [llength $definition] == 0} {
|
|
|
|
set location $expect_out(1,string)
|
|
|
|
exp_continue
|
|
|
|
} else {
|
|
|
|
# Exit this expect loop, with a result indicating failure.
|
|
|
|
set definition {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-re "The symbol `${macro}' has no definition as a C/C\\+\\+ preprocessor macro\[^\r\n\]*\[\r\n\]" {
|
|
|
|
# `location' and `definition' should be empty when we see
|
|
|
|
# this message.
|
|
|
|
if {[llength $location] == 0 && [llength $definition] == 0} {
|
|
|
|
set definition undefined
|
|
|
|
exp_continue
|
|
|
|
} else {
|
|
|
|
# Exit this expect loop, with a result indicating failure.
|
|
|
|
set definition {}
|
|
|
|
}
|
|
|
|
}
|
2009-04-29 09:51:33 +02:00
|
|
|
-re "^\[\r\n\]* included at \[^\r\n\]*(${filepat}):${nonzero}\[\r\n\]" {
|
2002-06-11 22:27:50 +02:00
|
|
|
# `location' should *not* be empty when we see this
|
|
|
|
# message. It should have recorded at least the initial
|
|
|
|
# `Defined at ' message (for definitions) or ` at' message
|
|
|
|
# (for undefined symbols).
|
|
|
|
if {[llength $location] != 0} {
|
|
|
|
lappend location $expect_out(1,string)
|
|
|
|
exp_continue
|
|
|
|
} else {
|
|
|
|
# Exit this expect loop, with a result indicating failure.
|
|
|
|
set definition {}
|
|
|
|
}
|
|
|
|
}
|
2009-04-29 09:51:33 +02:00
|
|
|
-re "^\[\r\n\]*at \[^\r\n\]*(${filepat}):${nonzero}\[\r\n\]" {
|
2002-06-11 22:27:50 +02:00
|
|
|
# This appears after a `has no definition' message.
|
|
|
|
# `location' should be empty when we see it.
|
|
|
|
if {[string compare $definition undefined] == 0 \
|
|
|
|
&& [llength $location] == 0} {
|
|
|
|
set location $expect_out(1,string)
|
|
|
|
exp_continue
|
|
|
|
} else {
|
|
|
|
# Exit this expect loop, with a result indicating failure.
|
|
|
|
set definition {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-re "#define ${macro} (\[^\r\n\]*)\[\r\n\]" {
|
|
|
|
# `definition' should be empty when we see this message.
|
|
|
|
if {[string compare $definition ""] == 0} {
|
|
|
|
set definition $expect_out(1,string)
|
|
|
|
exp_continue
|
|
|
|
} else {
|
|
|
|
# Exit this expect loop, with a result indicating failure.
|
|
|
|
set definition {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-re "has no preprocessor macro information.*$gdb_prompt $" {
|
|
|
|
set definition no-macro-info
|
|
|
|
}
|
|
|
|
-re "$gdb_prompt $" {
|
|
|
|
# Exit the expect loop; let the existing value of `definition'
|
|
|
|
# indicate failure or success.
|
|
|
|
}
|
|
|
|
timeout {
|
|
|
|
set definition timeout
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if {$debug_me} {exp_internal 0}
|
|
|
|
|
|
|
|
switch -exact -- $definition {
|
|
|
|
no-macro-info { return no-macro-info }
|
|
|
|
timeout { return timeout }
|
2009-05-30 09:58:42 +02:00
|
|
|
undefined { return undefined }
|
2002-06-11 22:27:50 +02:00
|
|
|
default {
|
|
|
|
if {[llength $location] >= 1} {
|
|
|
|
return [concat $location [list $definition]]
|
|
|
|
} else {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Call info_macro to show the definition of MACRO. Expect a result of
|
|
|
|
# EXPECTED. Use WHERE in pass/fail messages to identify the context.
|
|
|
|
# Return non-zero if we should abort the entire test file, or zero if
|
|
|
|
# we can continue.
|
|
|
|
proc check_macro {macro expected where} {
|
|
|
|
set func_def [info_macro $macro]
|
|
|
|
if {[string compare $func_def $expected] == 0} {
|
|
|
|
pass "info macro $macro $where"
|
|
|
|
} else {
|
|
|
|
switch -exact -- $func_def {
|
|
|
|
no-macro-info {
|
|
|
|
xfail "executable includes no macro debugging information"
|
|
|
|
return 1
|
|
|
|
}
|
2009-05-30 09:58:42 +02:00
|
|
|
undefined {
|
|
|
|
fail "info macro $macro $where (undefined)"
|
|
|
|
return 1
|
|
|
|
}
|
2002-06-11 22:27:50 +02:00
|
|
|
timeout {
|
|
|
|
fail "info macro $macro $where (timeout)"
|
|
|
|
}
|
|
|
|
default {
|
|
|
|
fail "info macro $macro $where"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
2009-02-18 23:24:37 +01:00
|
|
|
|
2002-06-11 22:27:50 +02:00
|
|
|
|
|
|
|
# List the function FUNC, and then show the definition of MACRO,
|
|
|
|
# expecting the result EXPECTED.
|
|
|
|
proc list_and_check_macro {func macro expected} {
|
2009-02-18 23:24:37 +01:00
|
|
|
gdb_test "list $func" ".*${func}.*" "list $func for $macro"
|
2002-06-11 22:27:50 +02:00
|
|
|
return [check_macro $macro $expected "after `list $func'"]
|
|
|
|
}
|
|
|
|
|
2009-11-12 20:37:40 +01:00
|
|
|
gdb_test "list main" ".*main.*" "list main for support check"
|
|
|
|
set macro_support "unknown"
|
|
|
|
gdb_test_multiple "info source" "Test macro information" {
|
|
|
|
-re "Includes preprocessor macro info\..*$gdb_prompt $" {
|
|
|
|
set macro_support 1
|
|
|
|
verbose "Source has macro information"
|
|
|
|
}
|
|
|
|
-re "Does not include preprocessor macro info\..*$gdb_prompt $" {
|
|
|
|
set macro_support 0
|
|
|
|
verbose "Source has no macro information"
|
2009-05-30 09:58:42 +02:00
|
|
|
}
|
2009-11-12 20:37:40 +01:00
|
|
|
default {
|
|
|
|
warning "couldn't check macro support (no valid response)."
|
2009-05-30 09:58:42 +02:00
|
|
|
}
|
2002-06-11 22:27:50 +02:00
|
|
|
}
|
2009-11-12 20:37:40 +01:00
|
|
|
if {$macro_support == 0} {
|
|
|
|
unsupported "Skipping test because debug information does not include macro information."
|
|
|
|
return 0
|
|
|
|
}
|
2009-05-30 09:58:42 +02:00
|
|
|
|
2009-11-12 20:37:40 +01:00
|
|
|
list_and_check_macro main WHERE {macscp1.c {before macscp1_3}}
|
2002-06-11 22:27:50 +02:00
|
|
|
list_and_check_macro macscp2_2 WHERE {macscp2.h macscp1.c {before macscp2_2}}
|
|
|
|
list_and_check_macro macscp3_2 WHERE {macscp3.h macscp1.c {before macscp3_2}}
|
|
|
|
|
|
|
|
|
2009-04-29 09:51:33 +02:00
|
|
|
# Assuming the current position inside program by `list' from above.
|
|
|
|
gdb_test "info macro FROM_COMMANDLINE" \
|
|
|
|
"Defined at \[^\r\n\]*:0\r\n-DFROM_COMMANDLINE=ARG"
|
|
|
|
|
|
|
|
|
2002-06-11 22:27:50 +02:00
|
|
|
# Although GDB's macro table structures distinguish between multiple
|
|
|
|
# #inclusions of the same file, GDB's other structures don't. So the
|
|
|
|
# `list' command here doesn't reliably select one #inclusion or the
|
|
|
|
# other, even though it could. It would be nice to eventually change
|
|
|
|
# GDB's structures to handle this correctly.
|
|
|
|
gdb_test "list macscp4_2_from_macscp2" ".*macscp4_2_, MACSCP4_INCLUSION.*"
|
|
|
|
switch -exact -- [info_macro WHERE] {
|
|
|
|
{macscp4.h macscp2.h macscp1.c {before macscp4_2_..., from macscp2.h}} {
|
|
|
|
pass "info macro WHERE after `list macscp_4_2_from_macscp2'"
|
|
|
|
}
|
|
|
|
{macscp4.h macscp3.h macscp1.c {before macscp4_2_..., from macscp3.h}} {
|
2010-05-26 00:23:07 +02:00
|
|
|
setup_kfail "gdb/555" *-*-*
|
2002-06-11 22:27:50 +02:00
|
|
|
fail "info macro WHERE after `list macscp_4_2_from_macscp2' (gdb/555)"
|
|
|
|
}
|
|
|
|
timeout {
|
|
|
|
fail "info macro WHERE after `list macscp_4_2_from_macscp2' (timeout)"
|
|
|
|
}
|
|
|
|
default { fail "info macro WHERE after `list macscp_4_2_from_macscp2'" }
|
|
|
|
}
|
|
|
|
|
|
|
|
gdb_test "list macscp4_2_from_macscp3" ".*macscp4_2_, MACSCP4_INCLUSION.*"
|
|
|
|
switch -exact -- [info_macro WHERE] {
|
|
|
|
{macscp4.h macscp3.h macscp1.c {before macscp4_2_..., from macscp3.h}} {
|
|
|
|
pass "info macro WHERE after `list macscp_4_2_from_macscp3'"
|
|
|
|
}
|
|
|
|
{macscp4.h macscp2.h macscp1.c {before macscp4_2_..., from macscp2.h}} {
|
2010-05-26 00:23:07 +02:00
|
|
|
setup_kfail "gdb/555" *-*-*
|
2002-06-11 22:27:50 +02:00
|
|
|
fail "info macro WHERE after `list macscp_4_2_from_macscp3' (gdb/555)"
|
|
|
|
}
|
|
|
|
timeout {
|
|
|
|
fail "info macro WHERE after `list macscp_4_2_from_macscp3' (timeout)"
|
|
|
|
}
|
|
|
|
default { fail "info macro WHERE after `list macscp_4_2_from_macscp3'" }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#### Test the selection of the macro scope by the current frame.
|
|
|
|
|
|
|
|
### A table of functions, in the order they will be reached, which is
|
|
|
|
### also the order they appear in the preprocessed output. Each entry
|
|
|
|
### has the form {FUNCNAME WHERE KFAILWHERE}, where:
|
|
|
|
### - FUNCNAME is the name of the function,
|
|
|
|
### - WHERE is the definition we expect to see for the macro `WHERE', as
|
|
|
|
### returned by `info_macro', and
|
|
|
|
### - KFAILWHERE is an alternate definition which should be reported
|
|
|
|
### as a `known failure', due to GDB's inability to distinguish multiple
|
|
|
|
### #inclusions of the same file.
|
|
|
|
### KFAILWHERE may be omitted.
|
|
|
|
|
|
|
|
set funcs {
|
|
|
|
{
|
|
|
|
macscp1_1
|
|
|
|
{macscp1.c {before macscp1_1}}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
macscp2_1
|
|
|
|
{macscp2.h macscp1.c {before macscp2_1}}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
macscp4_1_from_macscp2
|
|
|
|
{macscp4.h macscp2.h macscp1.c {before macscp4_1_..., from macscp2.h}}
|
|
|
|
{macscp4.h macscp3.h macscp1.c {before macscp4_1_..., from macscp3.h}}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
macscp4_2_from_macscp2
|
|
|
|
{macscp4.h macscp2.h macscp1.c {before macscp4_2_..., from macscp2.h}}
|
|
|
|
{macscp4.h macscp3.h macscp1.c {before macscp4_2_..., from macscp3.h}}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
macscp2_2
|
|
|
|
{macscp2.h macscp1.c {before macscp2_2}}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
macscp1_2
|
|
|
|
{macscp1.c {before macscp1_2}}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
macscp3_1
|
|
|
|
{macscp3.h macscp1.c {before macscp3_1}}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
macscp4_1_from_macscp3
|
|
|
|
{macscp4.h macscp3.h macscp1.c {before macscp4_1_..., from macscp3.h}}
|
|
|
|
{macscp4.h macscp2.h macscp1.c {before macscp4_1_..., from macscp2.h}}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
macscp4_2_from_macscp3
|
|
|
|
{macscp4.h macscp3.h macscp1.c {before macscp4_2_..., from macscp3.h}}
|
|
|
|
{macscp4.h macscp2.h macscp1.c {before macscp4_2_..., from macscp2.h}}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
macscp3_2
|
|
|
|
{macscp3.h macscp1.c {before macscp3_2}}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
macscp1_3
|
|
|
|
{macscp1.c {before macscp1_3}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-25 23:47:11 +02:00
|
|
|
proc maybe_kfail { func test_name } {
|
|
|
|
# We can't get the right scope info when we're stopped in
|
|
|
|
# the macro4_ functions.
|
|
|
|
if {[string match macscp4_* $func]} {
|
|
|
|
kfail gdb/555 "$test_name"
|
|
|
|
} else {
|
|
|
|
fail "$test_name"
|
|
|
|
}
|
|
|
|
}
|
2002-06-11 22:27:50 +02:00
|
|
|
|
|
|
|
# Start the program running.
|
|
|
|
if {! [runto_main]} {
|
|
|
|
fail "macro tests suppressed: couldn't run to main"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# Set a breakpoint on each of the functions.
|
|
|
|
foreach func_entry $funcs {
|
|
|
|
set func [lindex $func_entry 0]
|
|
|
|
gdb_test "break $func" "Breakpoint.*"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Run to each of the breakpoints and check the definition (or lack
|
|
|
|
# thereof) of each macro.
|
|
|
|
for {set i 0} {$i < [llength $funcs]} {incr i} {
|
|
|
|
set func_entry [lindex $funcs $i]
|
|
|
|
set func [lindex $func_entry 0]
|
|
|
|
set expected [lindex $func_entry 1]
|
|
|
|
set kfail_expected [lindex $func_entry 2]
|
|
|
|
|
|
|
|
# Run to the breakpoint for $func.
|
|
|
|
gdb_test "continue" "Breakpoint $decimal, $func .*" "continue to $func"
|
|
|
|
|
|
|
|
# Check the macro WHERE.
|
|
|
|
set result [info_macro WHERE]
|
|
|
|
if {[string compare $result $expected] == 0} {
|
|
|
|
pass "info macro WHERE stopped in $func"
|
|
|
|
} elseif {[string compare $result $kfail_expected] == 0} {
|
2010-05-26 00:23:07 +02:00
|
|
|
setup_kfail "gdb/555" *-*-*
|
2002-06-11 22:27:50 +02:00
|
|
|
fail "info macro WHERE stopped in $func (gdb/555)"
|
|
|
|
} elseif {[string compare $result timeout] == 0} {
|
|
|
|
fail "info macro WHERE stopped in $func (timeout)"
|
|
|
|
} else {
|
|
|
|
fail "info macro WHERE stopped in $func"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check that the BEFORE_<func> macros for all prior functions are
|
|
|
|
# #defined, and that those for all subsequent functions are not.
|
|
|
|
for {set j 0} {$j < [llength $funcs]} {incr j} {
|
|
|
|
if {$j != $i} {
|
|
|
|
set func_j_entry [lindex $funcs $j]
|
|
|
|
set func_j [lindex $func_j_entry 0]
|
|
|
|
|
|
|
|
set before_macro "BEFORE_[string toupper $func_j]"
|
|
|
|
set test_name \
|
|
|
|
"$before_macro defined/undefined when stopped at $func"
|
|
|
|
set result [info_macro $before_macro]
|
|
|
|
|
|
|
|
if {$j < $i} {
|
|
|
|
if {[llength $result] >= 2 && \
|
|
|
|
[string compare [lindex $result end] {}] == 0} {
|
|
|
|
pass $test_name
|
|
|
|
} elseif {[string compare $result timeout] == 0} {
|
|
|
|
fail "$test_name (timeout)"
|
|
|
|
} else {
|
2008-04-25 23:47:11 +02:00
|
|
|
maybe_kfail $func "$test_name"
|
2002-06-11 22:27:50 +02:00
|
|
|
}
|
|
|
|
} elseif {$j > $i} {
|
|
|
|
switch -- [lindex $result end] {
|
|
|
|
undefined { pass $test_name }
|
|
|
|
timeout { fail "$test_name (timeout)" }
|
|
|
|
default {
|
2008-04-25 23:47:11 +02:00
|
|
|
maybe_kfail $func "$test_name"
|
2002-06-11 22:27:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set until_macro "UNTIL_[string toupper $func_j]"
|
|
|
|
set test_name \
|
|
|
|
"$until_macro defined/undefined when stopped at $func"
|
|
|
|
set result [info_macro $until_macro]
|
|
|
|
|
|
|
|
if {$j <= $i} {
|
|
|
|
switch -- [lindex $result end] {
|
|
|
|
undefined { pass $test_name }
|
|
|
|
timeout { fail "$test_name (timeout)" }
|
|
|
|
default {
|
2008-04-25 23:47:11 +02:00
|
|
|
maybe_kfail $func "$test_name"
|
2002-06-11 22:27:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} elseif {$j > $i} {
|
|
|
|
if {[llength $result] >= 2 && \
|
|
|
|
[string compare [lindex $result end] {}] == 0} {
|
|
|
|
pass $test_name
|
|
|
|
} elseif {[string compare $result timeout] == 0} {
|
|
|
|
fail "$test_name (timeout)"
|
|
|
|
} else {
|
2008-04-25 23:47:11 +02:00
|
|
|
maybe_kfail $func "$test_name"
|
2002-06-11 22:27:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-05-04 00:30:51 +02:00
|
|
|
|
|
|
|
gdb_test "break [gdb_get_line_number "set breakpoint here"]" \
|
|
|
|
"Breakpoint.*at.* file .*, line.*" \
|
|
|
|
"breakpoint macscp_expr"
|
|
|
|
|
|
|
|
gdb_test "continue" "foo = 0;.*" "continue to macsp_expr"
|
|
|
|
|
gdb
PR macros/2564:
* c-exp.y (macro_original_text, expansion_obstack,
expression_macro_scope): New globals.
(scan_macro_expansion): New function.
(scanning_macro_expansion): Likewise.
(finished_macro_expansion): Likewise.
(scan_macro_cleanup): Likewise.
(c_parse): Find macro scope. Initialize obstack.
* c-lang.h (scan_macro_expansion, scanning_macro_expansion,
finished_macro_expansion, expression_macro_lookup_func,
expression_macro_lookup_baton): Remove.
* c-lang.c (scan_macro_expansion, scanning_macro_expansion,
finished_macro_expansion, expression_macro_lookup_func,
expression_macro_lookup_baton): Remove.
(macro_original_text, macro_expanded_text,
c_preprocess_and_parse): Remove.
(c_language_defn, cplus_language_defn, asm_language_defn,
minimal_language_defn): Use c_parse.
gdb/testsuite
* gdb.base/macscp.exp: Print "address.addr".
* gdb.base/macscp1.c (struct outer): New struct.
(address): New global.
2008-12-11 19:30:28 +01:00
|
|
|
gdb_test "print address.addr" \
|
|
|
|
" = 0" \
|
|
|
|
"print address.addr"
|
|
|
|
|
2008-09-30 18:53:06 +02:00
|
|
|
gdb_test "print MACRO_TO_EXPAND" \
|
|
|
|
"No symbol \"MACRO_TO_EXPAND\" in current context\." \
|
2008-05-04 00:30:51 +02:00
|
|
|
"print expression with macro before define."
|
|
|
|
|
2009-02-18 23:24:37 +01:00
|
|
|
gdb_test "next" "foo = 1;" "next to definition 1"
|
2008-05-04 00:30:51 +02:00
|
|
|
|
2008-09-30 18:53:06 +02:00
|
|
|
gdb_test "print MACRO_TO_EXPAND" \
|
2008-05-04 00:30:51 +02:00
|
|
|
" = 0" \
|
|
|
|
"print expression with macro in scope."
|
|
|
|
|
2010-06-01 23:29:21 +02:00
|
|
|
gdb_test_no_output "macro define MACRO_TO_EXPAND 72" \
|
2008-07-18 22:55:33 +02:00
|
|
|
"user macro override"
|
|
|
|
|
2008-09-30 18:53:06 +02:00
|
|
|
gdb_test "print MACRO_TO_EXPAND" \
|
2008-07-18 22:55:33 +02:00
|
|
|
" = 72" \
|
|
|
|
"choose user macro"
|
|
|
|
|
2010-06-01 23:29:21 +02:00
|
|
|
gdb_test_no_output "macro undef MACRO_TO_EXPAND" \
|
2008-07-18 22:55:33 +02:00
|
|
|
"remove user override"
|
|
|
|
|
2008-09-30 18:53:06 +02:00
|
|
|
gdb_test "print MACRO_TO_EXPAND" \
|
2008-07-18 22:55:33 +02:00
|
|
|
" = 0" \
|
|
|
|
"print expression with macro after removing override"
|
|
|
|
|
2009-02-18 23:24:37 +01:00
|
|
|
gdb_test "next" "foo = 2;" "next to definition 2"
|
2008-05-04 00:30:51 +02:00
|
|
|
|
2008-09-30 18:53:06 +02:00
|
|
|
gdb_test "print MACRO_TO_EXPAND" \
|
|
|
|
"No symbol \"MACRO_TO_EXPAND\" in current context\." \
|
2008-05-04 00:30:51 +02:00
|
|
|
"print expression with macro after undef."
|
2008-07-18 22:55:33 +02:00
|
|
|
|
2010-06-01 23:29:21 +02:00
|
|
|
gdb_test_no_output "macro define MACRO_TO_EXPAND 5" \
|
2008-07-18 22:55:33 +02:00
|
|
|
"basic macro define"
|
|
|
|
|
2008-09-30 18:53:06 +02:00
|
|
|
gdb_test "print MACRO_TO_EXPAND" \
|
2008-07-18 22:55:33 +02:00
|
|
|
" = 5" \
|
|
|
|
"expansion of defined macro"
|
|
|
|
|
|
|
|
gdb_test "macro list" \
|
2008-09-30 18:53:06 +02:00
|
|
|
"macro define MACRO_TO_EXPAND 5" \
|
2008-07-18 22:55:33 +02:00
|
|
|
"basic macro list"
|
|
|
|
|
2010-06-01 23:29:21 +02:00
|
|
|
gdb_test_no_output "macro define MACRO_TO_EXPAND(x) x" \
|
2008-07-18 22:55:33 +02:00
|
|
|
"basic redefine, macro with args"
|
|
|
|
|
2008-09-30 18:53:06 +02:00
|
|
|
gdb_test "print MACRO_TO_EXPAND (7)" \
|
2008-07-18 22:55:33 +02:00
|
|
|
" = 7" \
|
|
|
|
"expansion of macro with arguments"
|
|
|
|
|
2010-06-01 23:29:21 +02:00
|
|
|
gdb_test_no_output "macro undef MACRO_TO_EXPAND" \
|
2008-07-18 22:55:33 +02:00
|
|
|
"basic macro undef"
|
|
|
|
|
2008-09-30 18:53:06 +02:00
|
|
|
gdb_test "print MACRO_TO_EXPAND" \
|
|
|
|
"No symbol \"MACRO_TO_EXPAND\" in current context\." \
|
2008-07-18 22:55:33 +02:00
|
|
|
"print expression with macro after user undef."
|
2008-07-27 03:58:01 +02:00
|
|
|
|
2008-08-14 20:03:22 +02:00
|
|
|
# Regression test; this used to crash.
|
|
|
|
gdb_test "macro define" \
|
|
|
|
"usage: macro define.*" \
|
|
|
|
"macro define with no arguments"
|
|
|
|
|
|
|
|
# Regression test; this used to crash.
|
|
|
|
gdb_test "macro undef" \
|
|
|
|
"usage: macro undef.*" \
|
|
|
|
"macro undef with no arguments"
|
|
|
|
|
2008-09-30 19:21:28 +02:00
|
|
|
# Completion tests.
|
|
|
|
|
|
|
|
# The macro FIFTY_SEVEN is in scope at this point.
|
|
|
|
send_gdb "p FIFTY_\t"
|
|
|
|
gdb_expect {
|
|
|
|
-re "^p FIFTY_SEVEN $"\
|
|
|
|
{ send_gdb "\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "^.* = 57.*$gdb_prompt $"\
|
|
|
|
{ pass "complete 'p FIFTY_SEVEN'"}
|
|
|
|
-re ".*$gdb_prompt $" { fail "complete 'p FIFTY_SEVEN'"}
|
|
|
|
timeout {fail "(timeout) complete 'p FIFTY_SEVEN'"}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-re ".*$gdb_prompt $" { fail "complete 'p FIFTY_SEVEN'" }
|
|
|
|
timeout { fail "(timeout) complete 'p FIFTY_SEVEN' 2" }
|
|
|
|
}
|
|
|
|
|
|
|
|
# The macro TWENTY_THREE is not in scope.
|
|
|
|
send_gdb "p TWENTY_\t"
|
|
|
|
gdb_expect {
|
|
|
|
-re "^p TWENTY_\\\x07$"\
|
|
|
|
{ send_gdb "\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "No symbol \"TWENTY_\" in current context\\..*$gdb_prompt $"\
|
|
|
|
{ pass "complete 'p TWENTY_'"}
|
|
|
|
-re ".*$gdb_prompt $" { fail "complete 'p TWENTY_'"}
|
|
|
|
timeout {fail "(timeout) complete 'p TWENTY_'"}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-re ".*$gdb_prompt $" { fail "complete 'p TWENTY_'" }
|
|
|
|
timeout { fail "(timeout) complete 'p TWENTY_' 2" }
|
|
|
|
}
|
|
|
|
|
|
|
|
# The macro FORTY_EIGHT was undefined and thus is not in scope.
|
|
|
|
send_gdb "p FORTY_\t"
|
|
|
|
gdb_expect {
|
|
|
|
-re "^p FORTY_\\\x07$"\
|
|
|
|
{ send_gdb "\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "No symbol \"FORTY_\" in current context\\..*$gdb_prompt $"\
|
|
|
|
{ pass "complete 'p FORTY_'"}
|
|
|
|
-re ".*$gdb_prompt $" { fail "complete 'p FORTY_'"}
|
|
|
|
timeout {fail "(timeout) complete 'p FORTY_'"}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-re ".*$gdb_prompt $" { fail "complete 'p FORTY_'" }
|
|
|
|
timeout { fail "(timeout) complete 'p FORTY_' 2" }
|
|
|
|
}
|
|
|
|
|
2010-06-01 23:29:21 +02:00
|
|
|
gdb_test_no_output "macro define TWENTY_THREE 25" \
|
2008-09-30 19:21:28 +02:00
|
|
|
"defining TWENTY_THREE"
|
|
|
|
|
|
|
|
# User-defined macros are always in scope.
|
|
|
|
send_gdb "p TWENTY_\t"
|
|
|
|
gdb_expect {
|
|
|
|
-re "^p TWENTY_THREE $"\
|
|
|
|
{ send_gdb "\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "^.* = 25.*$gdb_prompt $"\
|
|
|
|
{ pass "complete 'p TWENTY_THREE'"}
|
|
|
|
-re ".*$gdb_prompt $" { fail "complete 'p TWENTY_THREE'"}
|
|
|
|
timeout {fail "(timeout) complete 'p TWENTY_THREE'"}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-re ".*$gdb_prompt $" { fail "complete 'p TWENTY_THREE'" }
|
|
|
|
timeout { fail "(timeout) complete 'p TWENTY_THREE' 2" }
|
|
|
|
}
|
|
|
|
|
2008-09-27 23:40:49 +02:00
|
|
|
# Splicing tests.
|
|
|
|
|
2008-07-27 03:58:01 +02:00
|
|
|
gdb_test "macro expand SPLICE(x, y)" \
|
2008-09-27 23:40:49 +02:00
|
|
|
"expands to: xy" \
|
|
|
|
"basic macro splicing"
|
|
|
|
|
2010-06-01 23:29:21 +02:00
|
|
|
gdb_test_no_output "macro define robotinvasion 2010" \
|
2008-09-27 23:40:49 +02:00
|
|
|
"define splice helper"
|
|
|
|
|
|
|
|
gdb_test "macro expand SPLICE(robot, invasion)" \
|
|
|
|
"expands to: *2010" \
|
|
|
|
"splicing plus expansion"
|
|
|
|
|
|
|
|
# Varargs tests.
|
|
|
|
|
2010-06-01 23:29:21 +02:00
|
|
|
gdb_test_no_output "macro define va_c99(...) varfunc (fixedarg, __VA_ARGS__)" \
|
2008-09-27 23:40:49 +02:00
|
|
|
"define first varargs helper"
|
|
|
|
|
2010-06-01 23:29:21 +02:00
|
|
|
gdb_test_no_output "macro define va2_c99(x, y, ...) varfunc (fixedarg, x, y, __VA_ARGS__)" \
|
2008-09-27 23:40:49 +02:00
|
|
|
"define second varargs helper"
|
|
|
|
|
2010-06-01 23:29:21 +02:00
|
|
|
gdb_test_no_output "macro define va_gnu(args...) varfunc (fixedarg, args)" \
|
2008-09-27 23:40:49 +02:00
|
|
|
"define third varargs helper"
|
|
|
|
|
2010-06-01 23:29:21 +02:00
|
|
|
gdb_test_no_output "macro define va2_gnu(args...) varfunc (fixedarg, ## args)" \
|
2008-09-27 23:40:49 +02:00
|
|
|
"define fourth varargs helper"
|
|
|
|
|
|
|
|
gdb_test "macro expand va_c99(one, two, three)" \
|
2008-10-09 18:49:47 +02:00
|
|
|
"expands to: *varfunc \\(fixedarg, *one, two, three\\)" \
|
2008-09-27 23:40:49 +02:00
|
|
|
"c99 varargs expansion"
|
|
|
|
|
|
|
|
gdb_test "macro expand va_c99()" \
|
2008-10-09 18:49:47 +02:00
|
|
|
"expands to: *varfunc \\(fixedarg, *\\)" \
|
2008-09-27 23:40:49 +02:00
|
|
|
"c99 varargs expansion without an argument"
|
|
|
|
|
|
|
|
gdb_test "macro expand va2_c99(one, two, three, four)" \
|
2008-10-09 18:49:47 +02:00
|
|
|
"expands to: *varfunc \\(fixedarg, *one, two, three, four\\)" \
|
2008-09-27 23:40:49 +02:00
|
|
|
"c99 varargs expansion, multiple formal arguments"
|
|
|
|
|
|
|
|
gdb_test "macro expand va_gnu(one, two, three, four)" \
|
2008-10-09 18:49:47 +02:00
|
|
|
"expands to: *varfunc \\(fixedarg, *one, two, three, four\\)" \
|
2008-09-27 23:40:49 +02:00
|
|
|
"gnu varargs expansion"
|
|
|
|
|
|
|
|
gdb_test "macro expand va_gnu()" \
|
2008-10-09 18:49:47 +02:00
|
|
|
"expands to: *varfunc \\(fixedarg, *\\)" \
|
2008-09-27 23:40:49 +02:00
|
|
|
"gnu varargs expansion without an argument"
|
|
|
|
|
|
|
|
gdb_test "macro expand va2_gnu()" \
|
2008-10-09 18:49:47 +02:00
|
|
|
"expands to: *varfunc \\(fixedarg\\)" \
|
2008-09-27 23:40:49 +02:00
|
|
|
"gnu varargs expansion special splicing without an argument"
|
|
|
|
|
|
|
|
# Stringification tests.
|
|
|
|
|
2010-06-01 23:29:21 +02:00
|
|
|
gdb_test_no_output "macro define str(x) #x" \
|
2008-09-27 23:40:49 +02:00
|
|
|
"define stringification macro"
|
|
|
|
|
2010-06-01 23:29:21 +02:00
|
|
|
gdb_test_no_output "macro define maude 5" \
|
2008-09-27 23:40:49 +02:00
|
|
|
"define first stringification helper"
|
|
|
|
|
2010-06-01 23:29:21 +02:00
|
|
|
gdb_test_no_output "macro define xstr(x) str(x)" \
|
2008-09-27 23:40:49 +02:00
|
|
|
"define second stringification helper"
|
|
|
|
|
|
|
|
gdb_test "print str(5)" \
|
|
|
|
" = \"5\"" \
|
|
|
|
"simple stringify"
|
|
|
|
|
|
|
|
gdb_test "print str(hi bob)" \
|
|
|
|
" = \"hi bob\"" \
|
|
|
|
"stringify with one space"
|
|
|
|
|
|
|
|
gdb_test "print str( hi bob )" \
|
|
|
|
" = \"hi bob\"" \
|
|
|
|
"stringify with many spaces"
|
|
|
|
|
|
|
|
gdb_test "print str(hi \"bob\")" \
|
|
|
|
" = \"hi \\\\\"bob\\\\\"\"" \
|
|
|
|
"stringify with quotes"
|
|
|
|
|
|
|
|
gdb_test "print str(hi \\bob\\)" \
|
|
|
|
" = \"hi \\\\\\\\bob\\\\\\\\\"" \
|
|
|
|
"stringify with backslashes"
|
|
|
|
|
|
|
|
gdb_test "print str(maude)" \
|
|
|
|
" = \"maude\"" \
|
|
|
|
"stringify without substitution"
|
|
|
|
|
|
|
|
gdb_test "print xstr(maude)" \
|
|
|
|
" = \"5\"" \
|
|
|
|
"stringify with substitution"
|
2008-12-12 18:03:37 +01:00
|
|
|
|
|
|
|
# Regression test for pp-number bug.
|
2010-06-01 23:29:21 +02:00
|
|
|
gdb_test_no_output "macro define si_addr fields.fault.si_addr" \
|
2008-12-12 18:03:37 +01:00
|
|
|
"define si_addr macro"
|
2010-06-01 23:29:21 +02:00
|
|
|
|
2008-12-12 18:03:37 +01:00
|
|
|
gdb_test "macro expand siginfo.si_addr" \
|
|
|
|
"expands to: siginfo.fields.fault.si_addr" \
|
|
|
|
"macro expand siginfo.si_addr"
|