1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26:01 +02:00

[280607] fixed copy-n-paste mistake in last commit. Also enhanced the documentation.

This commit is contained in:
John Cortell 2010-03-03 23:05:47 +00:00
parent cafa75507d
commit 293b055013

View file

@ -28,11 +28,37 @@ import java.util.regex.Pattern;
*/ */
public class CLIInfoThreadsInfo extends MIInfo { public class CLIInfoThreadsInfo extends MIInfo {
/**
* Matcher for 'info threads' output typically returned by gdbservers
* running on POSIX systems. Relevant output is in the form: <br>
* <p>
* <code>
* &lt;x&gt; Thread &lt;y&gt; (LWP &lt;z&gt;)
* </code>
*
* <p>
* Where 'y' is a hex number with a '0x' prefix.
*
* <p>
* Note that the output likely includes non-LWP threads, but they are
* intentionally ignored
*/
private static final Pattern RESULT_PATTERN_LWP = Pattern.compile( private static final Pattern RESULT_PATTERN_LWP = Pattern.compile(
"(^\\*?\\s*\\d+)(\\s*[Tt][Hh][Rr][Ee][Aa][Dd]\\s*)(0x[0-9a-fA-F]+|-?\\d+)(\\s*\\([Ll][Ww][Pp]\\s*)(\\d*)", Pattern.MULTILINE); //$NON-NLS-1$ "(^\\*?\\s*\\d+)(\\s*[Tt][Hh][Rr][Ee][Aa][Dd]\\s*)(0x[0-9a-fA-F]+|-?\\d+)(\\s*\\([Ll][Ww][Pp]\\s*)(\\d*)", Pattern.MULTILINE); //$NON-NLS-1$
/**
* Matcher for 'info threads' output typically returned by gdbservers running
* on non-POSIX systems. Output is in the more general form: <br>
* <p>
* <code>
* &lt;x&gt; Thread &lt;y&gt; (&lt;text&gt;)
* </code>
*
* <p>where 'y' is not necessarily numeric and (&lt;text&gt;) is optional
*/
private static final Pattern RESULT_PATTERN = Pattern.compile( private static final Pattern RESULT_PATTERN = Pattern.compile(
"(^\\*?\\s*\\d+)(\\s*[Tt][Hh][Rr][Ee][Aa][Dd]\\s*)(\\S+(\\s*\\(.*?\\))?)", Pattern.MULTILINE); //$NON-NLS-1$ "(^\\*?\\s*\\d+)(\\s*[Tt][Hh][Rr][Ee][Aa][Dd]\\s*)(\\S+(\\s*\\(.*?\\))?)", Pattern.MULTILINE); //$NON-NLS-1$
protected List<ThreadInfo> info; protected List<ThreadInfo> info;
public CLIInfoThreadsInfo(MIOutput out) { public CLIInfoThreadsInfo(MIOutput out) {
@ -84,8 +110,9 @@ public class CLIInfoThreadsInfo extends MIInfo {
protected void parseThreadInfo(String str, List<ThreadInfo> info) { protected void parseThreadInfo(String str, List<ThreadInfo> info) {
// Fetch the OS ThreadId & Find the current thread // Fetch the OS ThreadId & Find the current thread
// Here is an example output from GDB which shows normal threads as well as // Here is an example output from GDB which shows normal threads as well as
// LWP process threads // LWP process threads. We ignore non-LWP threads.
// //
// [example A]
// (gdb) info threads // (gdb) info threads
// 7 Thread 0x941c00 (sleeping) 0x0000000806c6d0df in pthread_mutexattr_init () from /usr/lib/libpthread.so.2 // 7 Thread 0x941c00 (sleeping) 0x0000000806c6d0df in pthread_mutexattr_init () from /usr/lib/libpthread.so.2
// 6 Thread 0x953000 (sleeping) 0x0000000806c6d0df in pthread_mutexattr_init () from /usr/lib/libpthread.so.2 // 6 Thread 0x953000 (sleeping) 0x0000000806c6d0df in pthread_mutexattr_init () from /usr/lib/libpthread.so.2
@ -94,21 +121,28 @@ public class CLIInfoThreadsInfo extends MIInfo {
// * 3 Thread 0x510400 (LWP 100132) 0x0000000806c7489c in pthread_testcancel () from /usr/lib/libpthread.so.2 // * 3 Thread 0x510400 (LWP 100132) 0x0000000806c7489c in pthread_testcancel () from /usr/lib/libpthread.so.2
// 2 Thread 0x510000 (runnable) 0x0000000806e468ec in read () from /lib/libc.so.6 // 2 Thread 0x510000 (runnable) 0x0000000806e468ec in read () from /lib/libc.so.6
// //
// Here is other output which will be handled // However, 'info threads' output varies, and depends on the gdbserver
// //
// [example B, observed with FreeBSD]
// (gdb) info threads // (gdb) info threads
// 6 Thread 1286 (tid 38473, running) 0x00000000 in ?? () // 6 Thread 1286 (tid 38473, running) 0x00000000 in ?? ()
// 5 Thread 1029 (tid 34369, running) 0x00000000 in ?? () // 5 Thread 1029 (tid 34369, running) 0x00000000 in ?? ()
// 4 Thread 772 (tid 39483, running) 0xd037eb94 in clock_gettime () // 4 Thread 772 (tid 39483, running) 0xd037eb94 in clock_gettime ()
// * 3 Thread 515 (tid 39741, running) 0x00000000 in ?? () // * 3 Thread 515 (tid 39741, running) 0x00000000 in ?? ()
// //
// It also turns out that GDB for Windows ( at least the one shipped with Wascana ) returns lower // [example C, observed with cygwin and mingw]
// case "thread" , so the code needs to be case-insensitive. Also since the original code wanted // 2 thread 5264.0x608 0x7c90eb94 in ntdll!LdrAccessResource ()
// to favor the LWP info, we will leave this in. Only if it does not come up with a match will we // from /cygdrive/c/WINDOWS/system32/ntdll.dll
// default to the more general algorithm. // * 1 thread 5264.0x16f8 main (argc=1, argv=0x661f00) at MultiThread.cc:16
//
// Note that windows gdbs returns lower case "thread" , so the matcher
// needs to be case-insensitive.
//
// The original code favored the format in example A and so we will
// continue to give it precedence. The newly added support for formats
// B and C will have lower precedence.
if(str.length() > 0 ){ if(str.length() > 0 ){
Matcher matcher = RESULT_PATTERN_LWP.matcher(str); Matcher matcher = RESULT_PATTERN_LWP.matcher(str); // example A
boolean isCurrentThread = false; boolean isCurrentThread = false;
if (matcher.find()) { if (matcher.find()) {
String id = matcher.group(1).trim(); String id = matcher.group(1).trim();
@ -119,7 +153,7 @@ public class CLIInfoThreadsInfo extends MIInfo {
info.add(new ThreadInfo(id, matcher.group(5), "", isCurrentThread)); //$NON-NLS-1$ info.add(new ThreadInfo(id, matcher.group(5), "", isCurrentThread)); //$NON-NLS-1$
} }
else { else {
matcher = RESULT_PATTERN_LWP.matcher(str); matcher = RESULT_PATTERN.matcher(str); // examples B and C
if (matcher.find()) { if (matcher.find()) {
String id = matcher.group(1).trim(); String id = matcher.group(1).trim();
if (id.charAt(0) == '*') { if (id.charAt(0) == '*') {