aboutsummaryrefslogtreecommitdiff
path: root/gas/macro.c
diff options
context:
space:
mode:
authorJan Beulich <jbeulich@suse.com>2022-12-13 09:11:53 +0100
committerJan Beulich <jbeulich@suse.com>2022-12-13 09:11:53 +0100
commit969b9a36506bfb386f8ce30f88f1a6a6ebbaca6e (patch)
tree7cc916e6db68595bb894cd1675fb0112038ab218 /gas/macro.c
parentf2e469cb476a8fff9841914af6f8b5dead5c553a (diff)
downloadbinutils-969b9a36506bfb386f8ce30f88f1a6a6ebbaca6e.zip
binutils-969b9a36506bfb386f8ce30f88f1a6a6ebbaca6e.tar.gz
binutils-969b9a36506bfb386f8ce30f88f1a6a6ebbaca6e.tar.bz2
gas: re-work line number tracking for macros and their expansions
The PR gas/16908 workaround aimed at uniformly reporting line numbers to reference macro invocation sites. As mentioned in a comment this may be desirable for small macros, but often isn't for larger ones. As a first step improve diagnostics to report both locations, while aiming at leaving generated debug info unaltered. Note that macro invocation context is lost for any diagnostics issued only after all input was processed (or more generally for any use of as_*_where(), as the functions can't know whether the passed in location is related to [part of] the present stack of locations). To maintain the intended workaround behavior for PR gas/16908, a new as_where() is introduced to "look through" macro invocations, while the existing as_where() is renamed (and used in only very few places for now). Down the road as_where() will likely want to return a list of (file,line) pairs.
Diffstat (limited to 'gas/macro.c')
-rw-r--r--gas/macro.c43
1 files changed, 17 insertions, 26 deletions
diff --git a/gas/macro.c b/gas/macro.c
index 3d5774e..c41b9c0 100644
--- a/gas/macro.c
+++ b/gas/macro.c
@@ -131,23 +131,21 @@ buffer_and_nest (const char *from, const char *to, sb *ptr,
else
from_len = strlen (from);
- /* Except for macros record the present source position, such that
- diagnostics and debug info will be properly associated with the
- respective original lines, rather than with the line of the ending
- directive (TO). */
- if (from == NULL || strcasecmp (from, "MACRO") != 0)
- {
- unsigned int line;
- char *linefile;
-
- as_where (&line);
- if (!flag_m68k_mri)
- linefile = xasprintf ("\t.linefile %u .", line + 1);
- else
- linefile = xasprintf ("\tlinefile %u .", line + 1);
- sb_add_string (ptr, linefile);
- xfree (linefile);
- }
+ /* Record the present source position, such that diagnostics and debug info
+ can be properly associated with the respective original lines, rather
+ than with the line of the ending directive (TO). */
+ {
+ unsigned int line;
+ char *linefile;
+
+ as_where_top (&line);
+ if (!flag_m68k_mri)
+ linefile = xasprintf ("\t.linefile %u .", line + 1);
+ else
+ linefile = xasprintf ("\tlinefile %u .", line + 1);
+ sb_add_string (ptr, linefile);
+ xfree (linefile);
+ }
while (more)
{
@@ -249,14 +247,8 @@ buffer_and_nest (const char *from, const char *to, sb *ptr,
}
/* PR gas/16908
- Apply and discard .linefile directives that appear within
- the macro. For long macros, one might want to report the
- line number information associated with the lines within
- the macro definition, but we would need more infrastructure
- to make that happen correctly (e.g. resetting the line
- number when expanding the macro), and since for short
- macros we clearly prefer reporting the point of expansion
- anyway, there's not an obviously better fix here. */
+ Apply .linefile directives that appear within the macro, alongside
+ keeping them for later expansion of the macro. */
if (from != NULL && strcasecmp (from, "MACRO") == 0
&& len >= 8 && strncasecmp (ptr->ptr + i, "linefile", 8) == 0)
{
@@ -267,7 +259,6 @@ buffer_and_nest (const char *from, const char *to, sb *ptr,
s_linefile (0);
restore_ilp ();
ptr->ptr[ptr->len] = saved_eol_char;
- ptr->len = line_start;
}
}