Support for "break *ADDRESS thread THREADNO"

Maciej W. Rozycki
2005-04-12T15:54:19Z

Hello,

The current version of gdb does not accept the "thread THREADNO" clause
for breakpoints at an address. I'm not sure if that's a bug or feature as
the info pages carefully avoid documenting what should happen in this
case, referring to source lines instead.

Anyway I've found the inability to set up such breakpoints an obstacle,
so I've implemented the missing bits for it to work. Here's the result.
I've run-time tested the C language bit only (i.e. c-exp.y), but the other
.y changes are essentially the same, so they should work as well.
Unfortunately I haven't found a way of testing the Ada part which is
significantly different; I hope it's OK.

2005-04-12 Maciej W. Rozycki <macro@mips.com>

* ada-lex.l: Support the "thread THREADNO" clause with breakpoints
at an address.
* c-exp.y (yylex): Likewise.
* f-exp.y (yylex): Likewise.
* jv-exp.y (yylex): Likewise.
* m2-exp.y (yylex): Likewise.
* objc-exp.y (yylex): Likewise.
* p-exp.y (yylex): Likewise.

This has been verified for the HEAD version with the test suite for the
i386-linux-gnu system natively with no regressions. Please consider.

Maciej

gdb-6.2.1-20050412-break-addr-thread-0.patch
Index: src/gdb/ada-lex.l
===================================================================
RCS file: /cvsroot/gcc/src-cvs/src/gdb/ada-lex.l,v
retrieving revision 1.2.1000.2
diff -u -p -r1.2.1000.2 ada-lex.l
--- src/gdb/ada-lex.l 5 Aug 2004 14:41:08 -0000 1.2.1000.2
+++ src/gdb/ada-lex.l 12 Apr 2005 14:25:15 -0000
@@ -191,8 +191,9 @@ static int find_dot_all (const char *);
tempbuf_len += yyleng-4;
}

-if {
- while (*lexptr != 'i' && *lexptr != 'I')
+if|thread {
+ while (*lexptr != 'i' && *lexptr != 'I'
+ && *lexptr != 't' && *lexptr != 'T')
lexptr -= 1;
yyrestart(NULL);
return 0;
Index: src/gdb/c-exp.y
===================================================================
RCS file: /cvsroot/gcc/src-cvs/src/gdb/c-exp.y,v
retrieving revision 1.23.1000.5
diff -u -p -r1.23.1000.5 c-exp.y
--- src/gdb/c-exp.y 26 Aug 2004 16:38:01 -0000 1.23.1000.5
+++ src/gdb/c-exp.y 12 Apr 2005 14:25:15 -0000
@@ -1620,12 +1620,11 @@ yylex ()
c = tokstart[++namelen];
}

- /* The token "if" terminates the expression and is NOT removed from
- the input stream. It doesn't count if it appears in the
- expansion of a macro. */
- if (namelen == 2
- && tokstart[0] == 'i'
- && tokstart[1] == 'f'
+ /* The tokens "if" and "thread" terminate the expression and are NOT
+ removed from the input stream. It doesn't count if it appears in
+ the expansion of a macro. */
+ if (((namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
+ || (namelen == 6 && strncmp (tokstart, "thread", 6) == 0))
&& ! scanning_macro_expansion ())
{
return 0;
Index: src/gdb/f-exp.y
===================================================================
RCS file: /cvsroot/gcc/src-cvs/src/gdb/f-exp.y,v
retrieving revision 1.13.1000.2
diff -u -p -r1.13.1000.2 f-exp.y
--- src/gdb/f-exp.y 5 Aug 2004 14:41:15 -0000 1.13.1000.2
+++ src/gdb/f-exp.y 12 Apr 2005 14:25:15 -0000
@@ -1103,10 +1103,11 @@ yylex ()
|| (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
c = tokstart[++namelen]);

- /* The token "if" terminates the expression and is NOT
- removed from the input stream. */
-
- if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
+ /* The tokens "if" and "thread" terminate the expression and are NOT
+ removed from the input stream. It doesn't count if it appears in
+ the expansion of a macro. */
+ if ((namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
+ || (namelen == 6 && strncmp (tokstart, "thread", 6) == 0))
return 0;

lexptr += namelen;
Index: src/gdb/jv-exp.y
===================================================================
RCS file: /cvsroot/gcc/src-cvs/src/gdb/jv-exp.y,v
retrieving revision 1.16.1000.1
diff -u -p -r1.16.1000.1 jv-exp.y
--- src/gdb/jv-exp.y 10 Dec 2003 19:29:42 -0000 1.16.1000.1
+++ src/gdb/jv-exp.y 12 Apr 2005 14:25:15 -0000
@@ -1118,9 +1118,11 @@ yylex ()
c = tokstart[++namelen];
}

- /* The token "if" terminates the expression and is NOT
- removed from the input stream. */
- if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
+ /* The tokens "if" and "thread" terminate the expression and are NOT
+ removed from the input stream. It doesn't count if it appears in
+ the expansion of a macro. */
+ if ((namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
+ || (namelen == 6 && strncmp (tokstart, "thread", 6) == 0))
{
return 0;
}
Index: src/gdb/m2-exp.y
===================================================================
RCS file: /cvsroot/gcc/src-cvs/src/gdb/m2-exp.y,v
retrieving revision 1.11.1000.1
diff -u -p -r1.11.1000.1 m2-exp.y
--- src/gdb/m2-exp.y 10 Dec 2003 19:29:42 -0000 1.11.1000.1
+++ src/gdb/m2-exp.y 12 Apr 2005 14:25:15 -0000
@@ -981,9 +981,11 @@ yylex ()
c = tokstart[++namelen])
;

- /* The token "if" terminates the expression and is NOT
- removed from the input stream. */
- if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
+ /* The tokens "if" and "thread" terminate the expression and are NOT
+ removed from the input stream. It doesn't count if it appears in
+ the expansion of a macro. */
+ if ((namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
+ || (namelen == 6 && strncmp (tokstart, "thread", 6) == 0))
{
return 0;
}
Index: src/gdb/objc-exp.y
===================================================================
RCS file: /cvsroot/gcc/src-cvs/src/gdb/objc-exp.y,v
retrieving revision 1.14.1000.2
diff -u -p -r1.14.1000.2 objc-exp.y
--- src/gdb/objc-exp.y 5 Aug 2004 14:41:19 -0000 1.14.1000.2
+++ src/gdb/objc-exp.y 12 Apr 2005 14:25:15 -0000
@@ -1574,9 +1574,11 @@ yylex ()
c = tokstart[++namelen];
}

- /* The token "if" terminates the expression and is NOT
- removed from the input stream. */
- if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
+ /* The tokens "if" and "thread" terminate the expression and are NOT
+ removed from the input stream. It doesn't count if it appears in
+ the expansion of a macro. */
+ if ((namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
+ || (namelen == 6 && strncmp (tokstart, "thread", 6) == 0))
{
return 0;
}
Index: src/gdb/p-exp.y
===================================================================
RCS file: /cvsroot/gcc/src-cvs/src/gdb/p-exp.y,v
retrieving revision 1.25.1000.2
diff -u -p -r1.25.1000.2 p-exp.y
--- src/gdb/p-exp.y 5 Aug 2004 14:41:19 -0000 1.25.1000.2
+++ src/gdb/p-exp.y 12 Apr 2005 14:25:15 -0000
@@ -1354,9 +1354,11 @@ yylex ()

uptokstart = uptok(tokstart,namelen);

- /* The token "if" terminates the expression and is NOT
- removed from the input stream. */
- if (namelen == 2 && uptokstart[0] == 'I' && uptokstart[1] == 'F')
+ /* The tokens "if" and "thread" terminate the expression and are NOT
+ removed from the input stream. It doesn't count if it appears in
+ the expansion of a macro. */
+ if ((namelen == 2 && uptokstart[0] == 'I' && uptokstart[1] == 'F')
+ || (namelen == 6 && strncmp (uptokstart, "THREAD", 6) == 0))
{
return 0;
}