Mercurial > ecos
annotate packages/hal/common/current/src/thread-packets.c @ 191:678094f34118
Merge from eCos master repository on 2001-10-19-06:43:02-BST
| author | jlarmour |
|---|---|
| date | Fri, 19 Oct 2001 07:02:26 +0000 |
| parents | 435cced73e2f |
| children | e0c0827131d1 |
| rev | line source |
|---|---|
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
1 //======================================================================== |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
2 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
3 // thread-packets.c |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
4 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
5 // Provides multi-threaded debug support |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
6 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
7 //======================================================================== |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
8 //####COPYRIGHTBEGIN#### |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
9 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
10 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
11 // The contents of this file are subject to the Red Hat eCos Public License |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
12 // Version 1.1 (the "License"); you may not use this file except in |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
13 // compliance with the License. You may obtain a copy of the License at |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
14 // http://www.redhat.com/ |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
15 // |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
18 // License for the specific language governing rights and limitations under |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
19 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
20 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
21 // The Original Code is eCos - Embedded Configurable Operating System, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
22 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
24 // The Initial Developer of the Original Code is Red Hat. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
25 // Portions created by Red Hat are |
|
191
678094f34118
Merge from eCos master repository on 2001-10-19-06:43:02-BST
jlarmour
parents:
76
diff
changeset
|
26 // Copyright (C) 1998, 1999, 2000, 2001 Red Hat, Inc. |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
27 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
28 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
29 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
30 //####COPYRIGHTEND#### |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
31 //======================================================================== |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
32 //#####DESCRIPTIONBEGIN#### |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
33 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
34 // Author(s): Red Hat, nickg |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
35 // Contributors: Red Hat, nickg |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
36 // Date: 1998-08-25 |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
37 // Purpose: |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
38 // Description: Provides multi-threaded debug support |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
39 // Usage: |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
40 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
41 //####DESCRIPTIONEND#### |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
42 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
43 //======================================================================== |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
46
diff
changeset
|
44 |
| 2 | 45 // Define __ECOS__; allows all eCos specific additions to be easily identified. |
| 46 #define __ECOS__ | |
| 0 | 47 |
| 48 | |
| 2 | 49 // #ifdef __ECOS__ |
| 0 | 50 #include <pkgconf/hal.h> |
| 51 | |
| 52 #if defined(CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT) \ | |
| 53 && defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS) | |
| 2 | 54 // #endif // __ECOS__ |
| 0 | 55 |
| 56 /* FIXME: Scan this module for correct sizes of fields in packets */ | |
| 2 | 57 |
| 58 #ifdef __ECOS__ | |
| 59 #include <cyg/hal/dbg-threads-api.h> | |
| 60 #else // __ECOS__ | |
| 61 #include "dbg-threads-api.h" | |
| 62 #endif // __ECOS__ | |
| 0 | 63 |
| 64 /* This file should ALWAYS define debug thread support */ | |
| 65 /* Dont include the object in the link if you dont need the support */ | |
| 66 /* This is NOT the internal unit debug flag, it is a feature control */ | |
| 67 #if defined(DEBUG_THREADS) | |
| 68 #undef DEBUG_THREADS | |
| 69 #endif | |
| 70 | |
| 2 | 71 #define DEBUG_THREADS 1 |
| 72 #define UNIT_TEST 0 | |
| 73 #define GDB_MOCKUP 0 | |
| 0 | 74 |
| 75 | |
| 76 #define STUB_BUF_MAX 300 /* for range checking of packet lengths */ | |
| 77 | |
| 78 #include "thread-pkts.h" | |
| 79 | |
| 2 | 80 #ifdef __ECOS__ |
| 0 | 81 // Use HAL rather than board.h in eCos |
| 82 #include <cyg/hal/hal_stub.h> | |
| 2 | 83 #else // __ECOS__ |
| 84 #include "board.h" | |
| 85 #endif // __ECOS__ | |
| 86 | |
| 87 /* | |
| 88 * Export the continue and "general" (context) thread IDs from GDB. | |
| 89 */ | |
| 90 int _gdb_cont_thread ; | |
| 91 int _gdb_general_thread ; | |
| 0 | 92 |
| 93 #if !defined(PKT_DEBUG) | |
| 94 #define PKT_DEBUG 0 | |
| 95 #endif | |
| 96 extern void output_string(char * message) ; | |
| 97 | |
| 98 #if PKT_DEBUG | |
| 99 void output_threadid(char * title,threadref * ref) ; | |
| 100 #warning "PKT_DEBUG macros engaged" | |
| 101 #define PKT_TRACE(title,packet) \ | |
| 102 { output_string(title) ; output_string(packet) ; output_string("\n") ;} | |
| 103 #else | |
| 104 #define PKT_TRACE(title,packet) {} | |
| 105 #endif | |
| 106 | |
| 107 | |
| 108 /* This is going to be irregular because the various implementations | |
| 109 have adopted different names for registers. | |
| 110 It would be nice to fix them to have a common convention | |
| 111 _stub_registers | |
| 112 stub_registers | |
| 113 alt_stub_registers | |
| 114 */ | |
| 115 | |
| 116 extern target_register_t * _registers ; | |
| 117 /* A pointer to the current set of registers */ | |
|
191
678094f34118
Merge from eCos master repository on 2001-10-19-06:43:02-BST
jlarmour
parents:
76
diff
changeset
|
118 extern target_register_t registers[]; /* The current saved registers */ |
|
678094f34118
Merge from eCos master repository on 2001-10-19-06:43:02-BST
jlarmour
parents:
76
diff
changeset
|
119 extern target_register_t alt_registers[] ; |
| 0 | 120 /* Thread or saved process state */ |
| 121 | |
| 122 | |
| 2 | 123 static void stub_copy_registers( |
| 124 target_register_t * dest, | |
| 125 target_register_t *src | |
| 126 ) | |
| 0 | 127 { |
| 128 target_register_t * limit ; | |
| 129 limit = dest + NUMREGS ; | |
| 130 | |
| 131 while (dest < limit) *dest++ = *src++ ; | |
| 132 } | |
| 133 | |
| 2 | 134 #ifdef __ECOS__ |
| 135 void __stub_copy_registers(target_register_t * dest, | |
| 136 target_register_t *src) | |
| 137 { | |
| 138 stub_copy_registers(dest, src); | |
| 139 } | |
| 140 #endif // __ECOS__ | |
| 141 | |
| 0 | 142 extern int stubhex(char ch) ; |
| 143 | |
| 144 /* ----- STUB_PACK_NAK ----------------------------------- */ | |
| 145 /* Pack an error response into the response packet */ | |
| 146 | |
| 147 char * stub_pack_nak(char * outbuf) | |
| 148 { | |
| 149 *outbuf++ = 'E' ; | |
| 150 *outbuf++ = '0' ; | |
| 151 *outbuf++ = '2' ; | |
| 152 return outbuf ; | |
| 153 } /* stub_pack_nak */ | |
| 154 | |
| 155 /* ----- STUB_PACK_ACK -------------------------- */ | |
| 156 /* Pack an OK achnowledgement */ | |
| 157 char * stub_pack_ack(char * outbuf) | |
| 158 { | |
| 159 *outbuf++ = 'O' ; | |
| 160 *outbuf++ = 'K' ; | |
| 161 return outbuf ; | |
| 162 } /* stub_pack_ack */ | |
| 163 | |
| 164 /* ------- STUB_UNPACK_INT ------------------------------- */ | |
| 165 /* Unpack a few bytes and return its integer value */ | |
| 166 /* This is where I wish functions could return several values | |
| 167 I would also advance the buffer pointer */ | |
| 168 | |
| 169 int stub_unpack_int(char * buff,int fieldlength) | |
| 170 { | |
| 171 int retval = 0 ; | |
| 172 int nibble ; | |
| 173 while (fieldlength) | |
| 174 { nibble = stubhex(*buff++) ; | |
| 175 retval |= nibble ; | |
| 176 fieldlength-- ; | |
| 177 if (fieldlength) retval = retval << 4 ; | |
| 178 } | |
| 179 return retval ; | |
| 180 } /* stub_unpack_int */ | |
| 181 | |
| 182 static char * unpack_byte(char * buf, int * value) | |
| 183 { | |
| 184 *value = stub_unpack_int(buf,2) ; | |
| 185 return buf + 2 ; | |
| 186 } | |
| 187 | |
| 188 static char * unpack_int(char * buf, int * value) | |
| 189 { | |
| 190 *value = stub_unpack_int(buf,8) ; | |
| 191 return buf + 8 ; | |
| 192 } | |
| 193 | |
|
38
e7ba79f6d3a8
Merge from eCos master repository on 1999-09-23-20:10:25-BST
jlarmour
parents:
2
diff
changeset
|
194 /* We are NOT depending upon extensive libraries */ |
| 0 | 195 static int ishex(char ch,int *val) |
| 196 { | |
| 197 if ((ch >= 'a') && (ch <= 'f')) | |
| 198 { *val =ch - 'a' + 10 ; return 1 ; } | |
| 199 if ((ch >= 'A') && (ch <= 'F')) | |
| 200 { *val = ch - 'A' + 10 ; return 1 ;} | |
| 201 if ((ch >= '0') && (ch <= '9')) | |
| 202 { *val = ch - '0' ; return 1 ; } | |
| 203 return 0 ; | |
| 204 } /* ishex */ | |
| 205 | |
| 206 static char * unpack_nibble(char * buf,int * val) | |
| 207 { | |
| 208 ishex(*buf++,val) ; | |
| 209 return buf ; | |
| 210 } | |
| 211 | |
| 212 | |
| 213 static const char hexchars[] = "0123456789abcdef"; | |
| 214 | |
| 215 static char * pack_hex_byte(char * pkt, unsigned char byte) | |
| 216 { | |
| 217 *pkt++ = hexchars[(byte >> 4) & 0xf] ; | |
| 218 *pkt++ = hexchars[(byte & 0xf)] ; | |
| 219 return pkt ; | |
| 220 } /* pack_hex_byte */ | |
| 221 | |
| 2 | 222 #ifndef __ECOS__ |
| 0 | 223 /* ---- STUB_PACK_VARLEN_HEX ------------------------------------- */ |
| 224 /* Format a variable length stream of hex bytes */ | |
| 225 | |
| 226 static char * pack_varlen_hex( | |
| 2 | 227 char * pkt, |
| 228 unsigned int value) | |
| 0 | 229 { |
| 230 int i ; | |
| 231 static unsigned char n[8] ; | |
| 232 if (value == 0) | |
| 233 { | |
| 234 *pkt++ = '0' ; | |
| 235 return pkt ; | |
| 236 } | |
| 237 else | |
| 238 { | |
| 239 i = 8 ; | |
| 240 while (i-- >= 0 ) /* unpack nibbles into a char array */ | |
| 2 | 241 { |
| 242 n[i] = value & 0x0f ; | |
| 243 value = value >> 4 ; | |
| 244 } | |
|
38
e7ba79f6d3a8
Merge from eCos master repository on 1999-09-23-20:10:25-BST
jlarmour
parents:
2
diff
changeset
|
245 i = 0 ; /* we had decrmented it to -1 */ |
| 0 | 246 while (n[i] == 0 ) i++ ; /* drop leading zeroes */ |
| 247 while (i++ < 8) *pkt++ = hexchars[n[i]] ; /* pack the number */ | |
| 248 } | |
| 249 return pkt ; | |
| 250 } /* pack_varlen_hex */ | |
| 2 | 251 #endif // !__ECOS__ |
| 252 | |
| 0 | 253 |
| 254 /* ------ STUB_UNPACK_VARLEN_HEX -------------------------------- */ | |
| 255 /* Parse a stream of hex bytes which may be of variable length */ | |
| 256 /* return the pointer to the next char */ | |
| 257 /* modify a varparm containing the result */ | |
| 258 /* A failure would look like a non-increment of the buffer pointer */ | |
| 259 | |
| 260 /* This unpacks hex strings that may have been packed using sprintf(%x) */ | |
| 261 /* We assume some non-hex delimits them */ | |
| 262 | |
| 263 char * unpack_varlen_hex( | |
| 2 | 264 char * buff, /* packet to parse */ |
| 265 int * result) | |
| 0 | 266 { |
| 267 int nibble ; | |
| 268 int retval ; | |
| 269 retval = 0 ; | |
| 270 | |
| 271 while (ishex(*buff,&nibble)) | |
| 272 { | |
| 273 buff++ ; | |
| 274 retval = retval << 4 ; | |
| 275 retval |= nibble & 0x0f ; | |
| 276 } | |
| 277 *result = retval ; | |
| 278 return buff ; | |
| 279 } /* stub_unpack_varlen_int */ | |
| 280 | |
| 281 | |
| 282 /* ------ UNPACK_THREADID ------------------------------- */ | |
| 283 /* A threadid is a 64 bit quantity */ | |
| 284 | |
| 285 #define BUFTHREADIDSIZ 16 /* encode 64 bits in 16 chars of hex */ | |
| 286 | |
| 287 static char * unpack_threadid(char * inbuf, threadref * id) | |
| 288 { | |
| 289 char * altref ; | |
| 290 char * limit = inbuf + BUFTHREADIDSIZ ; | |
| 291 int x,y ; | |
| 292 altref = (char *) id ; | |
| 293 | |
| 294 while (inbuf < limit) | |
| 295 { | |
| 296 x = stubhex(*inbuf++) ; | |
| 297 y = stubhex(*inbuf++) ; | |
| 298 *altref++ = (x << 4) | y ; | |
| 299 } | |
| 300 return inbuf ; | |
| 301 } /* unpack_threadid */ | |
| 302 | |
| 303 | |
| 304 | |
| 305 /* Pack an integer use leading zeroes */ | |
| 306 static char * pack_int(char * buf,int value) | |
| 307 { | |
| 308 buf = pack_hex_byte(buf,(value>> 24)& 0xff) ; | |
| 309 buf = pack_hex_byte(buf,(value >>16)& 0xff) ; | |
| 310 buf = pack_hex_byte(buf,(value >>8) & 0x0ff) ; | |
| 311 buf = pack_hex_byte(buf,(value & 0xff)) ; | |
| 312 return buf ; | |
| 313 } /* pack_int */ | |
| 314 | |
| 315 | |
| 316 /* -------- PACK_STRING ---------------------------------------------- */ | |
| 317 /* This stupid string better not contain any funny characters */ | |
| 318 /* Also, the GDB protocol will not cope with NULLs in the | |
| 319 string or at the end of it. | |
| 320 While is is posable to encapsulate the protocol in ays that | |
| 321 preclude filtering for # I am assuming this is a constraint. | |
| 322 */ | |
| 323 | |
| 324 static char * pack_raw_string(char * pkt,char * string) | |
| 325 { | |
| 326 char ch ; | |
| 327 while (0 != (ch = *string++)) *pkt++ = ch ; | |
| 328 return pkt ; | |
| 329 } | |
| 330 | |
| 331 static char * pack_string( | |
| 2 | 332 char * pkt, |
| 333 char * string) | |
| 0 | 334 { |
| 335 char ch ; | |
| 2 | 336 #ifdef __ECOS__ |
| 0 | 337 int len = 0; |
| 338 char *s = string; | |
| 339 while( *s++ ) len++; | |
| 2 | 340 #else // __ECOS__ |
| 341 int len ; | |
| 342 len = strlen(string) ; | |
| 343 #endif // __ECOS | |
| 0 | 344 if (len > 200 ) len = 200 ; /* Bigger than most GDB packets, junk??? */ |
| 345 pkt = pack_hex_byte(pkt,len) ; | |
| 346 while (len-- > 0) | |
| 347 { | |
| 348 ch = *string++ ; | |
| 349 if ((ch == '\0') || (ch == '#')) ch = '*' ; /* Protect encapsulation */ | |
| 350 *pkt++ = ch ; | |
| 351 } | |
| 352 return pkt ; | |
| 353 } /* pack_string */ | |
| 354 | |
| 355 | |
| 356 /* ----- STUB_PACK_THREADID --------------------------------------------- */ | |
| 357 /* Convert a binary 64 bit threadid and pack it into a xmit buffer */ | |
| 358 /* Return the advanced buffer pointer */ | |
| 359 | |
| 360 static char * pack_threadid(char * pkt, threadref * id) | |
| 361 { | |
| 362 char * limit ; | |
| 363 unsigned char * altid ; | |
| 364 altid = (unsigned char *) id ; | |
| 365 limit = pkt + BUFTHREADIDSIZ ; | |
| 366 while (pkt < limit) pkt = pack_hex_byte(pkt,*altid++) ; | |
| 367 return pkt ; | |
| 368 } /* stub_pack_threadid */ | |
| 369 | |
|
38
e7ba79f6d3a8
Merge from eCos master repository on 1999-09-23-20:10:25-BST
jlarmour
parents:
2
diff
changeset
|
370 /* UNFORTUNATELY, not all of the extended debugging system has yet been |
|
e7ba79f6d3a8
Merge from eCos master repository on 1999-09-23-20:10:25-BST
jlarmour
parents:
2
diff
changeset
|
371 converted to 64 but thread references and process identifiers. |
| 0 | 372 These routines do the conversion. |
| 373 An array of bytes is the correct treatment of an opaque identifier. | |
| 374 ints have endian issues. | |
| 375 */ | |
| 376 | |
| 377 static void int_to_threadref(threadref * id, int value) | |
| 378 { | |
| 379 unsigned char * scan ; | |
| 380 scan = (unsigned char *) id ; | |
| 381 { | |
| 382 int i = 4 ; | |
| 383 while (i--) *scan++ = 0 ; | |
| 384 } | |
| 385 *scan++ = (value >> 24) & 0xff ; | |
| 386 *scan++ = (value >> 16) & 0xff ; | |
| 387 *scan++ = (value >> 8) & 0xff ; | |
| 388 *scan++ = (value & 0xff) ; | |
| 389 } | |
| 390 | |
| 391 static int threadref_to_int(threadref * ref) | |
| 392 { | |
| 393 int value = 0 ; | |
| 394 unsigned char * scan ; | |
| 395 int i ; | |
| 396 | |
| 397 scan = (char *) ref ; | |
| 398 scan += 4 ; | |
| 399 i = 4 ; | |
| 400 while (i-- > 0) value = (value << 8) | ((*scan++) & 0xff) ; | |
| 401 return value ; | |
| 402 } /* threadref_to_int */ | |
| 403 | |
| 404 void copy_threadref(threadref * dest, threadref * src) | |
| 405 { | |
| 406 int i ; | |
| 407 unsigned char * csrc, * cdest ; | |
| 408 csrc = (unsigned char *) src ; | |
| 409 cdest = (unsigned char *) dest ; | |
| 410 i = 8 ; | |
| 411 while (i--) *cdest++ = *csrc++ ; | |
| 412 } | |
| 413 | |
| 414 | |
| 415 int threadmatch( | |
| 2 | 416 threadref * dest , |
| 417 threadref * src | |
| 418 ) | |
| 0 | 419 { |
| 420 unsigned char * srcp, * destp ; | |
| 421 int i , result ; | |
| 422 srcp = (char *) src ; | |
| 423 destp = (char *) dest ; | |
| 424 i = 8 ; | |
| 425 result = 1 ; | |
| 426 while (i-- > 0 ) result &= (*srcp++ == *destp++) ? 1 : 0 ; | |
| 427 return result ; | |
| 2 | 428 } /* threadmatch */ |
| 0 | 429 |
| 430 | |
| 431 | |
| 432 static char * Tpkt_threadtag = "thread:" ; | |
| 433 | |
| 434 /* ----- STUB_PACK_TPKT_THREADID ------------------------------------ */ | |
| 435 /* retreive, tag and insert a thread identifier into a T packet. */ | |
| 436 /* Insert nothing if the thread identifier is not available */ | |
| 437 | |
| 438 char * stub_pack_Tpkt_threadid(char * pkt) | |
| 439 { | |
| 440 static threadref thread ; | |
| 441 int fmt = 0 ; /* old format */ | |
| 442 PKT_TRACE("Tpkt-id","---") ; | |
| 443 if (dbg_currthread(&thread)) | |
| 444 { | |
| 445 pkt = pack_raw_string(pkt,Tpkt_threadtag) ; | |
| 446 if (fmt) | |
| 2 | 447 pkt = pack_threadid(pkt,&thread) ; |
| 0 | 448 else |
| 2 | 449 /* Until GDB lengthens its thread ids, we have to MASH |
| 450 the threadid into somthing shorter. PLEASE FIX GDB */ | |
| 451 pkt = pack_int(pkt,threadref_to_int(&thread)) ; | |
| 0 | 452 *pkt++ = ';' ; /* terminate variable length int */ |
| 453 *pkt = '\0' ; /* Null terminate to allow string to be printed, no++ */ | |
| 454 } | |
| 455 PKT_TRACE("packedTpkt","--") ; | |
| 456 return pkt ; | |
| 457 } /* stub_pack_Tpkt_threadid */ | |
| 458 | |
| 2 | 459 long stub_get_currthread (void) |
| 460 { | |
| 461 threadref thread ; | |
| 462 | |
| 463 if (dbg_currthread(&thread)) | |
| 464 return threadref_to_int(&thread) ; | |
| 465 else | |
| 466 return 0 ; | |
| 467 } | |
| 0 | 468 |
| 469 void stub_pkt_currthread( | |
| 2 | 470 char * inbuf, |
| 471 char * outbuf, | |
| 472 int bufmax) | |
| 0 | 473 { |
| 474 threadref thread ; | |
| 475 char * base_out ; | |
| 476 base_out = outbuf ; | |
| 477 | |
| 478 if (dbg_currthread(&thread)) | |
| 479 { | |
| 2 | 480 *outbuf++ = 'Q' ; |
|
46
797268ecc331
Merge from eCos master repository on 1999-10-19-18:55:31-BST
jlarmour
parents:
38
diff
changeset
|
481 *outbuf++ = 'C' ; /* FIXME: Is this a reasonable code */ |
| 2 | 482 outbuf = pack_int(outbuf, threadref_to_int(&thread)) ; /* Short form */ |
| 0 | 483 } |
| 484 else outbuf = stub_pack_nak(outbuf) ; | |
| 485 *outbuf = '\0' ; /* terminate response packet */ | |
| 486 PKT_TRACE("stub_pkt_currthread(resp) ",base_out) ; | |
| 487 } /* stub_pkt_currthread */ | |
| 488 | |
| 489 /* ----- STUB_PKT_THREAD_ALIVE --------------------------------- */ | |
| 490 /* Answer the thread alive query */ | |
| 491 | |
| 2 | 492 static int thread_alive (int id) |
| 493 { | |
| 494 threadref thread ; | |
| 495 struct cygmon_thread_debug_info info ; | |
| 496 | |
| 497 int_to_threadref(&thread, id) ; | |
| 498 if (dbg_threadinfo(&thread, &info) && | |
| 499 info.context_exists) | |
| 500 return 1 ; | |
| 501 else | |
| 502 return 0 ; | |
| 503 } | |
| 504 | |
| 0 | 505 void stub_pkt_thread_alive(char * inbuf, |
| 2 | 506 char * outbuf, |
| 507 int bufmax) | |
| 0 | 508 { |
| 509 char * prebuf = inbuf ; | |
| 510 int result ; | |
| 511 | |
| 512 if (prebuf != (inbuf = unpack_varlen_hex(inbuf,&result))) | |
| 513 { | |
| 2 | 514 if (thread_alive(result)) |
| 515 { | |
| 516 outbuf = stub_pack_ack(outbuf) ; | |
| 517 *outbuf = '\0' ; | |
| 518 return ; | |
| 519 } | |
| 0 | 520 } |
| 521 outbuf = stub_pack_nak(outbuf) ; | |
| 522 *outbuf = '\0' ; /* terminate the response message */ | |
| 523 } /* stub_pkt_thread_alive */ | |
| 524 | |
| 525 | |
| 526 | |
| 527 /* ----- STUB_PKT_CHANGETHREAD ------------------------------- */ | |
| 528 /* Switch the display of registers to that of a saved context */ | |
| 529 | |
| 530 /* Changing the context makes NO sense, although the packets define the | |
| 531 capability. Therefore, the option to change the context back does | |
| 532 call the function to change registers. Also, there is no | |
| 533 forced context switch. | |
| 534 'p' - New format, long long threadid, no special cases | |
| 2 | 535 'c' - Old format, id for continue, 32 bit threadid max, possably less |
| 536 -1 means continue all threads | |
| 0 | 537 'g' - Old Format, id for general use (other than continue) |
| 538 | |
| 539 replies: | |
| 540 OK for success | |
| 2 | 541 ENN for error |
| 0 | 542 */ |
| 543 | |
| 544 void stub_pkt_changethread( | |
| 2 | 545 char * inbuf, |
| 546 char * outbuf, | |
| 547 int bufmax) | |
| 0 | 548 { |
| 549 threadref id ; | |
| 550 int idefined = -1 ; | |
| 551 char ch ; | |
| 552 PKT_TRACE("setthread-pkt ",inbuf) ; | |
| 553 | |
| 554 /* Parse the incoming packet for a thread identifier */ | |
| 555 switch (ch = *inbuf++ ) /* handle various packet formats */ | |
| 556 { | |
| 557 case 'p' : /* New format: mode:8,threadid:64 */ | |
| 558 inbuf = unpack_nibble(inbuf,&idefined) ; | |
| 559 inbuf = unpack_threadid(inbuf,&id) ; /* even if startflag */ | |
| 560 break ; | |
| 561 case 'c' : /* old format , specify thread for continue */ | |
| 2 | 562 if (inbuf[0] == '-' && inbuf[1] == '1') /* Hc-1 */ |
| 563 _gdb_cont_thread = 0 ; | |
| 564 else | |
| 565 inbuf = unpack_varlen_hex(inbuf, &_gdb_cont_thread) ; | |
| 566 | |
| 567 if (_gdb_cont_thread == 0 || /* revert to any old thread */ | |
| 568 thread_alive(_gdb_cont_thread)) /* specified thread is alive */ | |
| 569 outbuf = stub_pack_ack(outbuf) ; | |
| 570 else | |
| 571 outbuf = stub_pack_nak(outbuf) ; | |
| 572 break ; | |
| 0 | 573 case 'g' : /* old format, specify thread for general operations */ |
| 574 /* OLD format: parse a variable length hex string */ | |
| 575 /* OLD format consider special thread ids */ | |
| 576 { | |
| 2 | 577 inbuf = unpack_varlen_hex(inbuf, &_gdb_general_thread) ; |
| 578 int_to_threadref(&id, _gdb_general_thread) ; | |
| 579 switch (_gdb_general_thread) | |
| 580 { | |
| 581 case 0 : /* pick a thread, any thread */ | |
| 582 idefined = 2 ; /* select original interrupted context */ | |
| 583 break ; | |
| 584 case -1 : /* all threads */ | |
| 585 idefined = 2 ; | |
| 586 break ; | |
| 587 default : | |
| 588 idefined = 1 ; /* select the specified thread */ | |
| 589 break ; | |
| 590 } | |
| 0 | 591 } |
| 592 break ; | |
| 593 default: | |
| 594 outbuf = stub_pack_nak(outbuf) ; | |
| 595 break ; | |
| 596 } /* handle various packet formats */ | |
| 597 | |
| 598 switch (idefined) | |
| 599 { | |
| 600 case -1 : | |
| 601 /* Packet not supported, already NAKed, no further action */ | |
| 602 break ; | |
| 603 case 0 : | |
| 604 /* Switch back to interrupted context */ | |
| 605 _registers = ®isters[0] ; | |
| 606 break ; | |
| 607 case 1 : | |
| 608 /* copy the saved registers into the backup registers */ | |
| 2 | 609 stub_copy_registers(alt_registers,registers) ; |
| 0 | 610 /* The OS will now update the values it has in a saved process context*/ |
| 611 if (dbg_getthreadreg(&id,NUMREGS,&alt_registers[0])) | |
| 2 | 612 { |
| 613 /* switch the registers pointer */ | |
| 614 _registers = &alt_registers[0] ; | |
| 615 outbuf = stub_pack_ack(outbuf) ; | |
| 616 } | |
| 0 | 617 else |
| 2 | 618 outbuf = stub_pack_nak(outbuf) ; |
| 0 | 619 break ; |
| 2 | 620 case 2 : |
| 621 /* switch to interrupted context */ | |
| 622 outbuf = stub_pack_ack(outbuf) ; | |
| 623 break ; | |
| 0 | 624 default: |
| 625 outbuf = stub_pack_nak(outbuf) ; | |
| 626 break ; | |
| 627 } | |
| 628 *outbuf = '\0' ; /* Terminate response pkt */ | |
| 2 | 629 } /* stub_pkt_changethread */ |
| 0 | 630 |
| 631 | |
| 632 /* ---- STUB_PKT_GETTHREADLIST ------------------------------- */ | |
| 633 /* Get a portion of the threadlist or process list */ | |
| 634 /* This may be part of a multipacket transaction */ | |
| 635 /* It would be hard to tell in the response packet the difference | |
| 636 between the end of list and an error in threadid encoding. | |
| 637 */ | |
| 638 | |
| 639 void stub_pkt_getthreadlist(char * inbuf, | |
| 2 | 640 char * outbuf, |
| 641 int bufmax) | |
| 0 | 642 { |
| 643 char * count_ptr ; | |
| 644 char * done_ptr ; | |
| 645 char * limit ; | |
| 646 int start_flag , batchsize , result , count ; | |
| 647 static threadref lastthread, nextthread ; | |
| 648 | |
| 649 #if PKT_DEBUG | |
| 650 char * r_base = outbuf ; | |
| 651 #endif | |
| 652 PKT_TRACE("pkt_getthreadlist: ",inbuf) ; | |
| 653 | |
| 654 count = 0 ; | |
| 655 inbuf = unpack_nibble(inbuf,&start_flag) ; | |
| 656 inbuf = unpack_byte(inbuf,&batchsize) ; | |
| 657 inbuf = unpack_threadid(inbuf,&lastthread) ; /* even if startflag */ | |
| 658 | |
| 659 /* Start building response packet */ | |
| 660 limit = outbuf + (bufmax - BUFTHREADIDSIZ - 10) ; /* id output packing limit */ | |
| 661 *outbuf++ = 'Q' ; | |
| 662 *outbuf++ = 'M' ; | |
| 663 | |
| 664 /* Default values for count and done fields, save ptr to repatch */ | |
| 665 count_ptr = outbuf ; /* save to repatch count */ | |
| 666 outbuf = pack_hex_byte(outbuf,0) ; | |
| 667 done_ptr = outbuf ; /* Backpatched later */ | |
| 668 *outbuf++ = '0' ; /* Done = 0 by default */ | |
| 669 outbuf = pack_threadid(outbuf,&lastthread) ; | |
| 670 | |
| 671 /* Loop through the threadid packing */ | |
| 672 while ((outbuf < limit) && (count < batchsize)) | |
| 673 { | |
| 674 result = dbg_threadlist(start_flag,&lastthread,&nextthread) ; | |
|
76
435cced73e2f
eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
jlarmour
parents:
66
diff
changeset
|
675 start_flag = 0 ; /* redundant but effective */ |
| 0 | 676 if (!result) |
| 2 | 677 { *done_ptr = '1' ; /* pack the done flag */ |
| 678 break ; | |
| 679 } | |
| 0 | 680 #if 0 /* DEBUG */ |
| 681 if (threadmatch(&lastthread,&nextthread)) | |
| 2 | 682 { |
| 683 output_string("FAIL: Threadlist, not incrementing\n") ; | |
| 684 *done_ptr = '1' ; | |
| 685 break ; | |
| 686 } | |
| 0 | 687 #endif |
| 688 count++ ; | |
| 689 outbuf = pack_threadid(outbuf,&nextthread) ; | |
| 690 copy_threadref(&lastthread,&nextthread) ; | |
| 691 } | |
| 692 pack_hex_byte(count_ptr,count) ;/* backpatch, Pack the count field */ | |
| 693 *outbuf = '\0' ; | |
| 694 PKT_TRACE("pkt_getthreadlist(resp) ",r_base) ; | |
| 695 } /* pkt_getthreadlist */ | |
| 696 | |
| 697 | |
| 698 | |
| 699 | |
| 700 /* ----- STUB_PKT_GETTHREADINFO ---------------------------------------- */ | |
| 701 /* Get the detailed information about a specific thread or process */ | |
| 702 | |
| 703 /* | |
| 704 Encoding: | |
| 705 'Q':8,'P':8,mask:16 | |
| 706 | |
| 707 Mask Fields | |
| 2 | 708 threadid:1, # always request threadid |
| 709 context_exists:2, | |
| 710 display:4, | |
| 711 unique_name:8, | |
| 712 more_display:16 | |
| 0 | 713 */ |
| 714 | |
| 715 void stub_pkt_getthreadinfo( | |
| 2 | 716 char * inbuf, |
| 717 char * outbuf, | |
| 718 int bufmax) | |
| 0 | 719 { |
| 720 int mask ; | |
| 721 int result ; | |
| 722 threadref thread ; | |
| 723 struct cygmon_thread_debug_info info ; | |
| 724 | |
| 725 info.context_exists = 0 ; | |
| 726 info.thread_display = 0 ; | |
| 727 info.unique_thread_name = 0 ; | |
| 728 info.more_display = 0 ; | |
| 729 | |
| 730 /* Assume the packet identification chars have already been | |
| 731 discarded by the packet demultiples routines */ | |
| 732 PKT_TRACE("PKT getthreadinfo",inbuf) ; | |
| 733 | |
| 734 inbuf = unpack_int(inbuf,&mask) ; | |
| 735 inbuf = unpack_threadid(inbuf,&thread) ; | |
| 736 | |
| 737 result = dbg_threadinfo(&thread,&info) ; /* Make system call */ | |
| 738 | |
| 739 if (result) | |
| 740 { | |
| 741 *outbuf++ = 'q' ; | |
| 742 *outbuf++ = 'p' ; | |
| 743 outbuf = pack_int(outbuf,mask) ; | |
| 744 outbuf = pack_threadid(outbuf,&info.thread_id) ; /* echo threadid */ | |
| 745 if (mask & 2) /* context-exists */ | |
| 2 | 746 { |
| 747 outbuf = pack_int(outbuf,2) ; /* tag */ | |
| 748 outbuf = pack_hex_byte(outbuf,2) ; /* length */ | |
| 749 outbuf = pack_hex_byte(outbuf,info.context_exists) ; | |
| 750 } | |
| 0 | 751 if ((mask & 4) && info.thread_display)/* display */ |
| 2 | 752 { |
| 753 outbuf = pack_int(outbuf,4) ; /* tag */ | |
| 754 outbuf = pack_string(outbuf,info.thread_display) ; | |
| 755 } | |
| 0 | 756 if ((mask & 8) && info.unique_thread_name) /* unique_name */ |
| 2 | 757 { |
| 758 outbuf = pack_int(outbuf,8) ; | |
| 759 outbuf = pack_string(outbuf,info.unique_thread_name) ; | |
| 760 } | |
| 0 | 761 if ((mask & 16) && info.more_display) /* more display */ |
| 2 | 762 { |
| 763 outbuf = pack_int(outbuf,16) ; /* tag 16 */ | |
| 764 outbuf = pack_string(outbuf,info.more_display) ; | |
| 765 } | |
| 0 | 766 } |
| 767 else | |
| 768 { | |
| 769 PKT_TRACE("FAIL: dbg_threadinfo\n", "") ; | |
| 770 outbuf = stub_pack_nak(outbuf) ; | |
| 771 } | |
| 772 *outbuf = '\0' ; | |
| 773 } /* stub_pkt_getthreadinfo */ | |
| 774 | |
| 2 | 775 int stub_lock_scheduler(int lock, /* 0 to unlock, 1 to lock */ |
| 776 int mode, /* 0 for step, 1 for continue */ | |
| 777 long id) /* current thread */ | |
| 778 { | |
| 779 threadref thread; | |
| 0 | 780 |
| 2 | 781 int_to_threadref(&thread, id) ; |
| 782 return dbg_scheduler(&thread, lock, mode) ; | |
| 783 } | |
| 0 | 784 |
| 785 | |
| 786 #if GDB_MOCKUP | |
| 787 /* ------ MATCHED GDB SIDE PACKET ENCODING AND PARSING ----------------- */ | |
| 788 | |
| 789 char * pack_nibble(char * buf, int nibble) | |
| 790 { | |
| 791 *buf++ = hexchars[(nibble & 0x0f)] ; | |
| 792 return buf ; | |
| 793 } /* pack_nibble */ | |
| 794 | |
| 795 #if 0 | |
| 796 static char * unpack_short(char * buf,int * value) | |
| 797 { | |
| 798 *value = stub_unpack_int(buf,4) ; | |
| 799 return buf + 4 ; | |
| 800 } | |
| 801 | |
| 802 static char * pack_short( | |
| 2 | 803 char * buf, |
| 804 unsigned int value) | |
| 0 | 805 { |
| 806 buf = pack_hex_byte(buf,(value >> 8) & 0xff) ; | |
| 807 buf = pack_hex_byte(buf,(value & 0xff)) ; | |
| 808 return buf ; | |
| 809 } /* pack_short */ | |
| 810 #endif | |
| 811 | |
| 812 | |
| 813 /* Generally, I dont bury xmit and receive calls inside packet formatters | |
| 814 and parsers | |
| 815 */ | |
| 816 | |
| 817 | |
| 818 | |
| 819 | |
| 820 /* ----- PACK_SETTHREAD_REQUEST ------------------------------------- */ | |
| 2 | 821 /* Encoding: ??? decode gdb/remote.c |
| 822 'Q':8,'p':8,idefined:8,threadid:32 ; | |
| 823 */ | |
| 0 | 824 |
| 825 char * pack_setthread_request( | |
| 2 | 826 char * buf, |
| 827 char fmt, /* c,g or, p */ | |
| 828 int idformat , | |
| 829 threadref * threadid ) | |
| 0 | 830 { |
| 831 *buf++ = fmt ; | |
| 832 | |
| 833 if (fmt == 'p') | |
| 834 { /* pack the long form */ | |
| 835 buf = pack_nibble(buf,idformat) ; | |
| 836 buf = pack_threadid(buf,threadid) ; | |
| 837 } | |
| 838 else | |
| 839 { /* pack the shorter form - Serious truncation */ | |
| 840 /* There are reserved identifieds 0 , -1 */ | |
| 841 int quickref = threadref_to_int(threadid) ; | |
| 842 buf = pack_varlen_hex(buf,quickref) ; | |
| 843 } | |
| 844 *buf++ = '\0' ; /* end_of_packet */ | |
| 845 return buf ; | |
| 846 } /* pack_setthread_request */ | |
| 847 | |
| 848 | |
| 849 | |
| 850 /* -------- PACK_THREADLIST-REQUEST --------------------------------- */ | |
| 851 /* Format: i'Q':8,i"L":8,initflag:8,batchsize:16,lastthreadid:32 */ | |
| 852 | |
| 853 | |
| 854 char * pack_threadlist_request( | |
| 2 | 855 char * pkt, |
| 856 int startflag, | |
| 857 int threadcount, | |
| 858 threadref * nextthread | |
| 859 ) | |
| 0 | 860 { |
| 861 *pkt++ = 'q' ; | |
| 862 *pkt++ = 'L' ; | |
| 863 pkt = pack_nibble(pkt,startflag) ; /* initflag 1 bytes */ | |
| 864 pkt = pack_hex_byte(pkt,threadcount) ; /* threadcount 2 bytes */ | |
| 865 pkt = pack_threadid(pkt,nextthread) ; /* 64 bit thread identifier */ | |
| 866 *pkt = '\0' ; | |
| 867 return pkt ; | |
| 868 } /* remote_threadlist_request */ | |
| 869 | |
| 870 | |
| 871 | |
| 872 | |
| 873 /* ---------- PARSE_THREADLIST_RESPONSE ------------------------------------ */ | |
| 874 /* Encoding: 'q':8,'M':8,count:16,done:8,argthreadid:64,(threadid:64)* */ | |
| 875 | |
| 876 int parse_threadlist_response( | |
| 2 | 877 char * pkt, |
| 878 threadref * original_echo, | |
| 879 threadref * resultlist, | |
| 880 int * doneflag) | |
| 0 | 881 { |
| 882 char * limit ; | |
| 883 int count, resultcount , done ; | |
| 884 resultcount = 0 ; | |
| 885 | |
| 886 /* assume the 'q' and 'M chars have been stripped */ | |
| 887 PKT_TRACE("parse-threadlist-response ",pkt) ; | |
| 888 limit = pkt + (STUB_BUF_MAX - BUFTHREADIDSIZ) ; /* done parse past here */ | |
| 2 | 889 pkt = unpack_byte(pkt,&count) ; /* count field */ |
| 0 | 890 pkt = unpack_nibble(pkt,&done) ; |
| 891 /* The first threadid is the argument threadid */ | |
| 892 pkt = unpack_threadid(pkt,original_echo) ; /* should match query packet */ | |
| 893 while ((count-- > 0) && (pkt < limit)) | |
| 894 { | |
| 895 pkt = unpack_threadid(pkt,resultlist++) ; | |
| 896 resultcount++ ; | |
| 897 } | |
| 898 if (doneflag) *doneflag = done ; | |
| 899 return resultcount ; /* successvalue */ | |
| 900 } /* parse_threadlist_response */ | |
| 901 | |
| 902 struct gdb_ext_thread_info | |
| 903 { | |
| 904 threadref threadid ; | |
| 905 int active ; | |
| 906 char display[256] ; | |
| 907 char shortname[32] ; | |
| 908 char more_display[256] ; | |
| 909 } ; | |
| 910 | |
| 911 | |
| 912 /* ----- PACK_THREAD_INFO_REQUEST -------------------------------- */ | |
| 913 | |
| 914 /* | |
| 915 threadid:1, # always request threadid | |
| 916 context_exists:2, | |
| 917 display:4, | |
| 918 unique_name:8, | |
| 919 more_display:16 | |
| 920 */ | |
| 921 | |
| 922 /* Encoding: 'Q':8,'P':8,mask:32,threadid:64 */ | |
| 923 | |
| 924 char * pack_threadinfo_request(char * pkt, | |
| 2 | 925 int mode, |
| 926 threadref * id | |
| 927 ) | |
| 0 | 928 { |
| 929 *pkt++ = 'Q' ; | |
| 930 *pkt++ = 'P' ; | |
| 931 pkt = pack_int(pkt,mode) ; /* mode */ | |
| 932 pkt = pack_threadid(pkt,id) ; /* threadid */ | |
| 933 *pkt = '\0' ; /* terminate */ | |
| 934 return pkt ; | |
| 935 } /* pack_thread_info_request */ | |
| 936 | |
| 937 | |
| 938 | |
| 939 static char * unpack_string( | |
| 2 | 940 char * src, |
| 941 char * dest, | |
| 942 int length) | |
| 0 | 943 { |
| 944 while (length--) *dest++ = *src++ ; | |
| 945 *dest = '\0' ; | |
| 946 return src ; | |
| 947 } /* unpack_string */ | |
| 948 | |
| 949 | |
| 950 void output_threadid(char * title,threadref * ref) | |
| 951 { | |
| 952 char hexid[20] ; | |
| 953 pack_threadid(&hexid[0],ref) ; /* Convert threead id into hex */ | |
| 954 hexid[16] = 0 ; | |
| 2 | 955 output_string(title) ; |
| 956 output_string(&hexid[0]) ; | |
| 957 output_string("\n") ; | |
| 0 | 958 } |
| 959 | |
| 960 /* ------ REMOTE_UPK_THREAD_INFO_RESPONSE ------------------------------- */ | |
| 961 /* Unpack the response of a detailed thread info packet */ | |
| 962 /* Encoding: i'Q':8,i'R':8,argmask:16,threadid:64,(tag:8,length:16,data:x)* */ | |
| 963 | |
| 964 #define TAG_THREADID 1 | |
| 965 #define TAG_EXISTS 2 | |
| 966 #define TAG_DISPLAY 4 | |
| 967 #define TAG_THREADNAME 8 | |
| 968 #define TAG_MOREDISPLAY 16 | |
| 969 | |
| 970 | |
| 971 int remote_upk_thread_info_response( | |
| 2 | 972 char * pkt, |
| 973 threadref * expectedref , | |
| 974 struct gdb_ext_thread_info * info) | |
| 0 | 975 { |
| 976 int mask, length ; | |
| 977 unsigned int tag ; | |
| 978 threadref ref ; | |
| 979 char * limit = pkt + 500 ; /* plausable parsing limit */ | |
| 980 int retval = 1 ; | |
| 981 | |
| 982 PKT_TRACE("upk-threadinfo ",pkt) ; | |
| 983 | |
| 984 /* info->threadid = 0 ; FIXME: implement zero_threadref */ | |
| 985 info->active = 0 ; | |
| 986 info->display[0] = '\0' ; | |
| 987 info->shortname[0] = '\0' ; | |
| 988 info->more_display[0] = '\0' ; | |
| 989 | |
| 990 /* Assume the characters indicating the packet type have been stripped */ | |
| 991 pkt = unpack_int(pkt,&mask) ; /* arg mask */ | |
| 992 pkt = unpack_threadid(pkt , &ref) ; | |
| 993 | |
| 994 if (! threadmatch(&ref,expectedref)) | |
| 995 { /* This is an answer to a different request */ | |
| 996 output_string("FAIL Thread mismatch\n") ; | |
| 997 output_threadid("ref ",&ref) ; | |
| 998 output_threadid("expected ",expectedref) ; | |
| 999 return 0 ; | |
| 1000 } | |
| 1001 copy_threadref(&info->threadid,&ref) ; | |
| 1002 | |
| 1003 /* Loop on tagged fields , try to bail if somthing goes wrong */ | |
| 1004 if (mask==0) output_string("OOPS NO MASK \n") ; | |
| 1005 | |
| 1006 while ((pkt < limit) && mask && *pkt) /* packets are terminated with nulls */ | |
| 1007 { | |
| 1008 pkt = unpack_int(pkt,&tag) ; /* tag */ | |
| 1009 pkt = unpack_byte(pkt,&length) ; /* length */ | |
| 1010 if (! (tag & mask)) /* tags out of synch with mask */ | |
| 2 | 1011 { |
| 1012 output_string("FAIL: threadinfo tag mismatch\n") ; | |
| 1013 retval = 0 ; | |
| 1014 break ; | |
| 1015 } | |
| 0 | 1016 if (tag == TAG_THREADID) |
| 2 | 1017 { |
| 1018 output_string("unpack THREADID\n") ; | |
| 1019 if (length != 16) | |
| 1020 { | |
| 1021 output_string("FAIL: length of threadid is not 16\n") ; | |
| 1022 retval = 0 ; | |
| 1023 break ; | |
| 1024 } | |
| 1025 pkt = unpack_threadid(pkt,&ref) ; | |
| 1026 mask = mask & ~ TAG_THREADID ; | |
| 1027 continue ; | |
| 1028 } | |
| 0 | 1029 if (tag == TAG_EXISTS) |
| 2 | 1030 { |
| 1031 info->active = stub_unpack_int(pkt,length) ; | |
| 1032 pkt += length ; | |
| 1033 mask = mask & ~(TAG_EXISTS) ; | |
| 1034 if (length > 8) | |
| 1035 { | |
| 1036 output_string("FAIL: 'exists' length too long\n") ; | |
| 1037 retval = 0 ; | |
| 1038 break ; | |
| 1039 } | |
| 1040 continue ; | |
| 1041 } | |
| 0 | 1042 if (tag == TAG_THREADNAME) |
| 2 | 1043 { |
| 1044 pkt = unpack_string(pkt,&info->shortname[0],length) ; | |
| 1045 mask = mask & ~TAG_THREADNAME ; | |
| 1046 continue ; | |
| 1047 } | |
| 0 | 1048 if (tag == TAG_DISPLAY) |
| 2 | 1049 { |
| 1050 pkt = unpack_string(pkt,&info->display[0],length) ; | |
| 1051 mask = mask & ~TAG_DISPLAY ; | |
| 1052 continue ; | |
| 1053 } | |
| 0 | 1054 if (tag == TAG_MOREDISPLAY) |
| 2 | 1055 { |
| 1056 pkt = unpack_string(pkt,&info->more_display[0],length) ; | |
| 1057 mask = mask & ~TAG_MOREDISPLAY ; | |
| 1058 continue ; | |
| 1059 } | |
| 0 | 1060 output_string("FAIL: unknown info tag\n") ; |
| 1061 break ; /* Not a tag we know about */ | |
| 1062 } | |
| 1063 return retval ; | |
| 1064 } /* parse-thread_info_response */ | |
| 1065 | |
| 1066 | |
| 2 | 1067 /* ---- REMOTE_PACK_CURRTHREAD_REQUEST ---------------------------- */ |
| 0 | 1068 /* This is a request to emit the T packet */ |
| 1069 | |
| 1070 /* FORMAT: 'q':8,'C' */ | |
| 1071 | |
| 1072 char * remote_pack_currthread_request(char * pkt ) | |
| 1073 { | |
| 1074 *pkt++ = 'q' ; | |
| 1075 *pkt++ = 'C' ; | |
| 1076 *pkt = '\0' ; | |
| 1077 return pkt ; | |
| 2 | 1078 } /* remote_pack_currthread_request */ |
| 0 | 1079 |
| 1080 | |
| 1081 /* ------- REMOTE_UPK_CURTHREAD_RESPONSE ----------------------- */ | |
| 1082 /* Unpack the interesting part of a T packet */ | |
| 1083 | |
| 1084 | |
| 1085 int remote_upk_currthread_response( | |
| 2 | 1086 char * pkt, |
| 1087 int *thr ) /* Parse a T packet */ | |
| 0 | 1088 { |
| 1089 int retval = 0 ; | |
| 1090 PKT_TRACE("upk-currthreadresp ",pkt) ; | |
| 1091 | |
| 1092 #if 0 | |
| 1093 { | |
| 1094 static char threadtag[8] = "thread" ; | |
| 1095 int retval = 0 ; | |
| 1096 int i , found ; | |
| 1097 char ch ; | |
| 1098 int quickid ; | |
| 1099 | |
| 1100 /* Unpack as a t packet */ | |
| 1101 while (((ch = *pkt++) != ':') /* scan for : thread */ | |
| 2 | 1102 && (ch != '\0')) /* stop at end of packet */ |
| 0 | 1103 |
| 1104 { | |
| 1105 found = 0 ; | |
| 1106 i = 0 ; | |
| 1107 while ((ch = *pkt++) == threadtag[i++]) ; | |
| 1108 if (i == 8) /* string match "thread" */ | |
| 2 | 1109 { |
| 1110 pkt = unpack_varlen_hex(pkt,&quickid) ; | |
| 1111 retval = 1; | |
| 1112 break ; | |
| 1113 } | |
| 0 | 1114 retval = 0 ; |
| 1115 } | |
| 1116 } | |
| 1117 #else | |
| 2 | 1118 pkt = unpack_threadid(pkt, thr) ; |
| 0 | 1119 retval = 1 ; |
| 1120 #endif | |
| 1121 return retval ; | |
| 1122 } /* remote_upk_currthread_response */ | |
| 1123 | |
| 1124 | |
| 1125 /* -------- REMOTE_UPK-SIMPLE_ACK --------------------------------- */ | |
| 1126 /* Decode a response which is eother "OK" or "Enn" | |
| 1127 fillin error code, fillin pkfag-1== undef, 0==nak, 1 == ack ; | |
| 1128 return advanced packet pointer */ | |
| 1129 | |
| 1130 | |
| 1131 char * remote_upk_simple_ack( | |
| 2 | 1132 char * buf, |
| 1133 int * pkflag, | |
| 1134 int * errcode) | |
| 0 | 1135 { |
| 1136 int lclerr = 0 ; | |
| 1137 char ch = *buf++ ; | |
| 1138 int retval = -1 ; /* Undefined ACK , a protocol error */ | |
| 1139 if (ch == 'E') /* NAK */ | |
| 1140 { | |
| 1141 buf = unpack_byte(buf,&lclerr) ; | |
| 1142 retval = 0 ; /* transaction failed, explicitly */ | |
| 1143 } | |
| 1144 else | |
| 1145 if ((ch == 'O') && (*buf++ == 'K')) /* ACK */ | |
| 1146 retval = 1 ; /* transaction succeeded */ | |
| 1147 *pkflag = retval ; | |
| 1148 *errcode = lclerr ; | |
| 1149 return buf ; | |
| 1150 } /* remote-upk_simple_ack */ | |
| 1151 | |
| 1152 | |
| 1153 /* -------- PACK_THREADALIVE_REQUEST ------------------------------- */ | |
| 1154 | |
| 1155 char * pack_threadalive_request( | |
| 2 | 1156 char * buf, |
| 1157 threadref * threadid) | |
| 0 | 1158 { |
| 1159 *buf++ = 'T' ; | |
| 1160 buf = pack_threadid(buf,threadid) ; | |
| 1161 *buf = '\0' ; | |
| 1162 return buf ; | |
| 1163 } /* pack_threadalive_request */ | |
| 1164 | |
| 1165 #endif /* GDB_MOCKUP */ | |
| 1166 | |
| 1167 /* ---------------------------------------------------------------------- */ | |
| 1168 /* UNIT_TESTS SUBSECTION */ | |
| 1169 /* ---------------------------------------------------------------------- */ | |
| 1170 | |
| 1171 | |
| 1172 #if UNIT_TEST | |
| 1173 extern void output_string(char * message) ; | |
| 1174 static char test_req[400] ; | |
| 1175 static char t_response[400] ; | |
| 1176 | |
| 1177 | |
| 1178 | |
| 1179 /* ----- DISPLAY_THREAD_INFO ---------------------------------------------- */ | |
| 1180 /* Use local cygmon string output utiities */ | |
| 1181 | |
| 1182 void display_thread_info(struct gdb_ext_thread_info * info) | |
| 1183 { | |
| 1184 | |
| 1185 output_threadid("Threadid: ",&info->threadid) ; | |
| 1186 /* short name */ | |
| 1187 output_string("Name: ") ; output_string(info->shortname) ; output_string("\n"); | |
| 1188 /* format display state */ | |
| 1189 output_string("State: ") ; output_string(info->display) ; output_string("\n") ; | |
| 1190 /* additional data */ | |
| 1191 output_string("other: ");output_string(info->more_display); | |
| 1192 output_string("\n\n"); | |
| 1193 } /* display_thread_info */ | |
| 1194 | |
| 1195 | |
| 1196 /* --- CURRTHREAD-TEST -------------------------------------------- */ | |
| 1197 static int currthread_test(threadref * thread) | |
| 1198 { | |
| 1199 int result ; | |
| 2 | 1200 int threadid ; |
| 0 | 1201 output_string("TEST: currthread\n") ; |
| 1202 remote_pack_currthread_request(test_req) ; | |
| 1203 stub_pkt_currthread(test_req+2,t_response,STUB_BUF_MAX) ; | |
| 2 | 1204 result = remote_upk_currthread_response(t_response+2, &threadid) ; |
| 0 | 1205 if (result) |
| 1206 { | |
| 1207 output_string("PASS getcurthread\n") ; | |
| 1208 /* FIXME: print the thread */ | |
| 1209 } | |
| 1210 else | |
| 1211 output_string("FAIL getcurrthread\n") ; | |
| 1212 return result ; | |
| 1213 } /* currthread_test */ | |
| 1214 | |
| 1215 /* ------ SETTHREAD_TEST ------------------------------------------- */ | |
| 1216 /* use a known thread from previous test */ | |
| 1217 | |
| 1218 static int setthread_test(threadref * thread) | |
| 1219 { | |
| 1220 int result, errcode ; | |
| 1221 output_string("TEST: setthread\n") ; | |
| 1222 | |
| 1223 pack_setthread_request(test_req,'p',1,thread) ; | |
| 1224 stub_pkt_changethread(test_req,t_response,STUB_BUF_MAX) ; | |
| 1225 remote_upk_simple_ack(t_response,&result,&errcode) ; | |
| 1226 switch (result) | |
| 1227 { | |
| 1228 case 0 : | |
| 1229 output_string("FAIL setthread\n") ; | |
| 1230 break ; | |
| 1231 case 1 : | |
| 1232 output_string("PASS setthread\n") ; | |
| 1233 break ; | |
| 1234 default : | |
| 1235 output_string("FAIL setthread -unrecognized response\n") ; | |
| 1236 break ; | |
| 1237 } | |
| 1238 return result ; | |
| 1239 } /* setthread_test */ | |
| 1240 | |
| 1241 | |
| 1242 /* ------ THREADACTIVE_TEST ---------------------- */ | |
| 1243 /* use known thread */ | |
| 1244 /* pack threadactive packet */ | |
| 1245 /* process threadactive packet */ | |
| 1246 /* parse threadactive response */ | |
| 1247 /* check results */ | |
| 1248 | |
| 1249 | |
| 1250 int threadactive_test(threadref * thread) | |
| 1251 { | |
| 1252 int result ; | |
| 1253 int errcode ; | |
| 1254 output_string("TEST: threadactive\n") ; | |
| 1255 pack_threadalive_request(test_req,thread) ; | |
| 1256 stub_pkt_thread_alive(test_req+1,t_response,STUB_BUF_MAX); | |
| 1257 remote_upk_simple_ack(t_response,&result,&errcode) ; | |
| 1258 switch (result) | |
| 1259 { | |
| 1260 case 0 : | |
| 1261 output_string("FAIL threadalive\n") ; | |
| 1262 break ; | |
| 1263 case 1 : | |
| 1264 output_string("PASS threadalive\n") ; | |
| 1265 break ; | |
| 1266 default : | |
| 1267 output_string("FAIL threadalive -unrecognized response\n") ; | |
| 1268 break ; | |
| 1269 } | |
| 1270 return result ; | |
| 1271 } /* threadactive_test */ | |
| 1272 | |
| 1273 /* ------ REMOTE_GET_THREADINFO -------------------------------------- */ | |
| 1274 int remote_get_threadinfo( | |
| 1275 threadref * threadid, | |
| 1276 int fieldset , /* TAG mask */ | |
| 1277 struct gdb_ext_thread_info * info | |
| 1278 ) | |
| 1279 { | |
| 1280 int result ; | |
| 1281 pack_threadinfo_request(test_req,fieldset,threadid) ; | |
| 1282 stub_pkt_getthreadinfo(test_req+2,t_response,STUB_BUF_MAX) ; | |
| 1283 result = remote_upk_thread_info_response(t_response+2,threadid,info) ; | |
| 1284 return result ; | |
| 1285 } /* remote_get-thrreadinfo */ | |
| 1286 | |
| 1287 | |
| 1288 static struct gdb_ext_thread_info test_info ; | |
| 1289 | |
| 1290 static int get_and_display_threadinfo(threadref * thread) | |
| 1291 { | |
| 1292 int mode ; | |
| 1293 int result ; | |
| 1294 /* output_string("TEST: get and display threadinfo\n") ; */ | |
| 1295 | |
| 1296 mode = TAG_THREADID | TAG_EXISTS | TAG_THREADNAME | |
| 1297 | TAG_MOREDISPLAY | TAG_DISPLAY ; | |
| 1298 result = remote_get_threadinfo(thread,mode,&test_info) ; | |
| 1299 if (result) display_thread_info(&test_info) ; | |
| 1300 #if 0 /* silent subtest */ | |
| 1301 if (result) | |
| 1302 output_string("PASS: get_and_display threadinfo\n") ; | |
| 1303 else | |
| 1304 output_string("FAIL: get_and_display threadinfo\n") ; | |
| 1305 #endif | |
| 1306 return result ; | |
| 1307 } /* get-and-display-threadinfo */ | |
| 1308 | |
| 1309 | |
| 1310 | |
| 1311 /* ----- THREADLIST_TEST ------------------------------------------ */ | |
| 1312 #define TESTLISTSIZE 16 | |
| 1313 #define TLRSIZ 2 | |
| 1314 static threadref test_threadlist[TESTLISTSIZE] ; | |
| 1315 | |
| 1316 static int threadlist_test(void) | |
| 1317 { | |
| 1318 int done, i , result_count ; | |
| 1319 int startflag = 1 ; | |
| 1320 int result = 1 ; | |
| 1321 int loopcount = 0 ; | |
| 1322 static threadref nextthread ; | |
| 1323 static threadref echo_nextthread ; | |
| 1324 | |
| 1325 output_string("TEST: threadlist\n") ; | |
| 1326 | |
| 1327 done = 0 ; | |
| 1328 while (! done) | |
| 1329 { | |
| 1330 if (loopcount++ > 10) | |
| 2 | 1331 { |
| 1332 result = 0 ; | |
| 1333 output_string("FAIL: Threadlist test -infinite loop-\n") ; | |
| 1334 break ; | |
| 1335 } | |
| 0 | 1336 pack_threadlist_request(test_req,startflag,TLRSIZ,&nextthread) ; |
| 1337 startflag = 0 ; /* clear for later iterations */ | |
| 1338 stub_pkt_getthreadlist(test_req+2,t_response,STUB_BUF_MAX); | |
| 1339 result_count = parse_threadlist_response(t_response+2, | |
| 2 | 1340 &echo_nextthread, |
| 1341 &test_threadlist[0],&done) ; | |
| 0 | 1342 if (! threadmatch(&echo_nextthread,&nextthread)) |
| 2 | 1343 { |
| 1344 output_string("FAIL: threadlist did not echo arg thread\n"); | |
| 1345 result = 0 ; | |
| 1346 break ; | |
| 1347 } | |
| 0 | 1348 if (result_count <= 0) |
| 2 | 1349 { |
| 1350 if (done != 0) | |
| 1351 { output_string("FAIL threadlist_test, failed to get list"); | |
| 1352 result = 0 ; | |
| 1353 } | |
| 1354 break ; | |
| 1355 } | |
| 0 | 1356 if (result_count > TLRSIZ) |
| 2 | 1357 { |
| 1358 output_string("FAIL: threadlist response longer than requested\n") ; | |
| 1359 result = 0 ; | |
| 1360 break ; | |
| 1361 } | |
| 0 | 1362 /* Setup to resume next batch of thread references , set nestthread */ |
| 1363 copy_threadref(&nextthread,&test_threadlist[result_count-1]) ; | |
| 1364 /* output_threadid("last-of-batch",&nextthread) ; */ | |
| 1365 i = 0 ; | |
| 1366 while (result_count--) | |
| 2 | 1367 { |
| 1368 if (0) /* two display alternatives */ | |
| 1369 output_threadid("truncatedisplay",&test_threadlist[i++]) ; | |
| 1370 else | |
| 1371 get_and_display_threadinfo(&test_threadlist[i++]) ; | |
| 1372 } | |
| 0 | 1373 |
| 1374 } | |
| 1375 if (!result) | |
| 1376 output_string("FAIL: threadlist test\n") ; | |
| 1377 else output_string("PASS: Threadlist test\n") ; | |
| 1378 return result ; | |
| 1379 } /* threadlist_test */ | |
| 1380 | |
| 1381 | |
| 1382 static threadref testthread ; | |
| 1383 | |
| 1384 | |
| 1385 int test_thread_support(void) | |
| 1386 { | |
| 1387 int result = 1 ; | |
| 1388 output_string("TESTING Thread support infrastructure\n") ; | |
| 1389 stub_pack_Tpkt_threadid(test_req) ; | |
| 1390 PKT_TRACE("packing the threadid -> ",test_req) ; | |
| 1391 result &= currthread_test(&testthread) ; | |
| 1392 result &= get_and_display_threadinfo(&testthread) ; | |
| 1393 result &= threadlist_test() ; | |
| 1394 result &= setthread_test(&testthread) ; | |
| 1395 if (result) | |
| 1396 output_string("PASS: UNITTEST Thread support\n") ; | |
| 1397 else | |
| 1398 output_string("FAIL: UNITTEST Thread support\n") ; | |
| 1399 return result ; | |
| 1400 } /* test-thread_support */ | |
| 1401 #endif /* UNIT_TEST */ | |
| 1402 | |
| 2 | 1403 // #ifdef __ECOS__ |
| 0 | 1404 #endif // ifdef CYGDBG_HAL_DEBUG_GDB_THREAD_SUPPORT... |
| 2 | 1405 // #endif // __ECOS__ |
