Mercurial > ecos
annotate packages/kernel/current/src/debug/dbg_gdb.cxx @ 30:641b639be825 ecos-sw-1999-08-16
Merge from eCos master repository on 1999-08-16-22:01:37-BST
| author | jlarmour |
|---|---|
| date | Mon, 16 Aug 1999 22:10:49 +0000 |
| parents | 01ce82f3e11a |
| children | c38311975d4f |
| rev | line source |
|---|---|
| 0 | 1 /*========================================================================== |
| 2 // | |
| 2 | 3 // dbg_gdb.c |
| 0 | 4 // |
| 2 | 5 // GDB Debugging Interface |
| 0 | 6 // |
| 7 //========================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
| 9 // | |
| 10 // ------------------------------------------- | |
| 11 // The contents of this file are subject to the Cygnus eCos Public License | |
| 12 // Version 1.0 (the "License"); you may not use this file except in | |
| 13 // compliance with the License. You may obtain a copy of the License at | |
| 14 // http://sourceware.cygnus.com/ecos | |
| 15 // | |
| 16 // Software distributed under the License is distributed on an "AS IS" | |
| 17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | |
| 18 // License for the specific language governing rights and limitations under | |
| 19 // the License. | |
| 20 // | |
| 21 // The Original Code is eCos - Embedded Cygnus Operating System, released | |
| 22 // September 30, 1998. | |
| 23 // | |
| 24 // The Initial Developer of the Original Code is Cygnus. Portions created | |
| 2 | 25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
| 0 | 26 // ------------------------------------------- |
| 27 // | |
| 28 //####COPYRIGHTEND#### | |
| 29 //========================================================================== | |
| 30 //#####DESCRIPTIONBEGIN#### | |
| 31 // | |
| 2 | 32 // Author(s): nickg |
| 33 // Contributors: nickg | |
| 34 // Date: 1998-08-22 | |
| 0 | 35 // Purpose: GDB Debugging Interface |
| 2 | 36 // Description: Interface for calls from GDB stubs into the OS. These |
| 0 | 37 // currently mostly support thread awareness. |
| 38 // | |
| 39 //####DESCRIPTIONEND#### | |
| 40 // | |
| 41 //========================================================================*/ | |
| 42 | |
| 43 #include <pkgconf/kernel.h> | |
| 44 #include <pkgconf/hal.h> // CYG_HAL_USE_ROM_MONITOR_CYGMON | |
| 45 | |
| 46 #ifdef CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT | |
| 47 | |
| 48 #include <cyg/kernel/ktypes.h> | |
| 49 | |
| 50 #include <cyg/kernel/thread.hxx> | |
| 51 #include <cyg/kernel/sched.hxx> | |
| 52 | |
| 53 #include <cyg/kernel/thread.inl> | |
| 54 #include <cyg/kernel/sched.inl> | |
| 55 | |
| 56 #include <cyg/hal/hal_arch.h> | |
| 57 #include <cyg/hal/hal_stub.h> | |
| 58 | |
| 59 extern "C" | |
| 60 { | |
| 61 #include <cyg/hal/dbg-threads-api.h> | |
| 62 }; | |
| 63 | |
| 64 #define USE_ID 1 | |
| 65 | |
| 66 #if (CYG_BYTEORDER == CYG_LSBFIRST) | |
| 67 | |
| 68 unsigned long swap32(unsigned long x) | |
| 69 { | |
| 70 unsigned long r = 0; | |
| 71 | |
| 72 r |= (x>>24)&0xFF; | |
| 73 r |= ((x>>16)&0xFF)<<8; | |
| 74 r |= ((x>>8)&0xFF)<<16; | |
| 75 r |= ((x)&0xFF)<<24; | |
| 76 | |
| 77 return r; | |
| 78 } | |
| 79 | |
| 80 #else | |
| 81 | |
| 82 #define swap32(x) ((unsigned long)(x)) | |
| 83 | |
| 84 #endif | |
| 85 | |
| 86 //-------------------------------------------------------------------------- | |
| 87 | |
| 88 externC int dbg_thread_capabilities(struct dbg_capabilities * cpb) | |
| 89 { | |
| 90 cpb->mask1 = has_thread_current | | |
| 91 has_thread_registers | | |
| 92 has_thread_reg_change | | |
| 93 has_thread_list | | |
| 94 has_thread_info ; | |
| 95 return 1 ; | |
| 96 } | |
| 97 | |
| 98 //-------------------------------------------------------------------------- | |
| 99 | |
| 100 static void dbg_make_threadref(Cyg_Thread *thread, threadref *ref ) | |
| 101 { | |
|
30
641b639be825
Merge from eCos master repository on 1999-08-16-22:01:37-BST
jlarmour
parents:
14
diff
changeset
|
102 // The following test tries to avoid accessing uninitialized pointers. |
|
641b639be825
Merge from eCos master repository on 1999-08-16-22:01:37-BST
jlarmour
parents:
14
diff
changeset
|
103 // This can happen if we take a breakpoint before the data is copied |
|
641b639be825
Merge from eCos master repository on 1999-08-16-22:01:37-BST
jlarmour
parents:
14
diff
changeset
|
104 // or the BSS zeroed. We currently assume that RAM will reset to zero |
|
641b639be825
Merge from eCos master repository on 1999-08-16-22:01:37-BST
jlarmour
parents:
14
diff
changeset
|
105 // or 0xff. If it is random, we have no hope. |
|
641b639be825
Merge from eCos master repository on 1999-08-16-22:01:37-BST
jlarmour
parents:
14
diff
changeset
|
106 |
|
641b639be825
Merge from eCos master repository on 1999-08-16-22:01:37-BST
jlarmour
parents:
14
diff
changeset
|
107 if( (CYG_ADDRWORD)thread == 0 || (CYG_ADDRWORD)thread == 0xffffffff ) |
|
10
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
108 { |
|
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
109 ((unsigned long *)ref)[0] = 0; |
|
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
110 ((unsigned long *)ref)[1] = 0; |
|
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
111 } |
|
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
112 else |
|
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
113 { |
|
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
114 cyg_uint16 id = thread->get_unique_id(); |
| 0 | 115 |
| 116 #if USE_ID | |
|
10
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
117 ((unsigned long *)ref)[0] = (unsigned long)thread; |
|
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
118 ((unsigned long *)ref)[1] = (unsigned long)swap32(id); |
| 0 | 119 #else |
|
10
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
120 ((unsigned long *)ref)[1] = (unsigned long)thread; |
|
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
121 ((unsigned long *)ref)[0] = (unsigned long)id; |
| 0 | 122 #endif |
|
10
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
123 } |
| 0 | 124 } |
| 125 | |
| 126 static Cyg_Thread *dbg_get_thread( threadref *ref) | |
| 127 { | |
| 128 #if USE_ID | |
| 129 | |
| 130 cyg_uint16 id = 0; | |
| 131 | |
| 132 id = (cyg_uint16)swap32(((unsigned long *)ref)[1]); | |
| 133 | |
| 134 Cyg_Thread *th = Cyg_Thread::get_list_head(); | |
| 135 while( th != 0 ) | |
| 136 { | |
| 137 if( th->get_unique_id() == id ) break; | |
| 138 th = th->get_list_next(); | |
| 139 } | |
| 140 | |
| 141 // if( thread->get_unique_id() != id ) th = 0; | |
| 142 | |
| 143 #else | |
| 144 | |
| 145 cyg_uint16 id = 0; | |
| 146 | |
| 147 Cyg_Thread *thread = (Cyg_Thread *)(((unsigned long *)ref)[1]); | |
| 148 id = (cyg_uint16)(((unsigned long *)ref)[0]); | |
| 149 | |
| 150 // Validate the thread. | |
| 151 Cyg_Thread *th = Cyg_Thread::get_list_head(); | |
| 152 while( th != 0 ) | |
| 153 { | |
| 154 if( th == thread ) break; | |
| 155 th = th->get_list_next(); | |
| 156 } | |
| 157 | |
| 158 // if( thread->get_unique_id() != id ) th = 0; | |
| 159 | |
| 160 #endif | |
| 161 | |
| 162 return th; | |
| 163 } | |
| 164 | |
| 165 //-------------------------------------------------------------------------- | |
| 166 | |
| 167 externC int dbg_currthread(threadref * varparm) | |
| 168 { | |
| 169 Cyg_Thread *thread = Cyg_Scheduler::get_current_thread(); | |
| 170 | |
| 171 dbg_make_threadref(thread, varparm ); | |
| 172 | |
| 173 return 1 ; | |
| 174 } | |
| 175 | |
| 176 //-------------------------------------------------------------------------- | |
| 177 | |
| 178 externC int dbg_currthread_id(void) | |
| 179 { | |
| 180 Cyg_Thread *thread = Cyg_Scheduler::get_current_thread(); | |
| 181 return thread->get_unique_id (); | |
| 182 } | |
| 183 | |
| 184 //-------------------------------------------------------------------------- | |
| 185 | |
| 186 externC int dbg_threadlist(int startflag, | |
| 2 | 187 threadref * lastthreadid, |
| 188 threadref * next_thread) | |
| 0 | 189 { |
| 190 Cyg_Thread *thread; | |
| 191 if( startflag ) | |
| 192 { | |
| 193 thread = Cyg_Thread::get_list_head(); | |
| 194 dbg_make_threadref(thread, next_thread); | |
| 195 } | |
| 196 else | |
| 197 { | |
| 198 thread = dbg_get_thread(lastthreadid); | |
| 199 | |
| 200 if( thread == 0 ) return 0; | |
| 201 thread = thread->get_list_next(); | |
| 202 | |
| 203 if( thread == 0 ) return 0; | |
| 204 dbg_make_threadref(thread, next_thread); | |
| 205 } | |
| 206 return 1 ; | |
| 207 } | |
| 208 | |
| 209 //-------------------------------------------------------------------------- | |
| 210 // Some support routines for manufacturing thread info strings | |
| 211 | |
| 212 static char *dbg_addstr(char *s, char *t) | |
| 213 { | |
| 214 while( (*s++ = *t++) != 0 ); | |
| 215 | |
| 216 return s-1; | |
| 217 } | |
| 218 | |
| 219 static char *dbg_addint(char *s, int n, int base) | |
| 220 { | |
| 221 char buf[16]; | |
| 222 char sign = '+'; | |
| 223 cyg_count8 bpos; | |
| 224 char *digits = "0123456789ABCDEF"; | |
| 225 | |
| 226 if( n < 0 ) n = -n, sign = '-'; | |
| 227 | |
| 228 /* Set pos to start */ | |
| 229 bpos = 0; | |
| 230 | |
| 231 /* construct digits into buffer in reverse order */ | |
| 232 if( n == 0 ) buf[bpos++] = '0'; | |
| 233 else while( n != 0 ) | |
| 234 { | |
| 235 cyg_ucount8 d = n % base; | |
| 236 buf[bpos++] = digits[d]; | |
| 237 n /= base; | |
| 238 } | |
| 239 | |
| 240 /* set sign if negative. */ | |
| 241 if( sign == '-' ) | |
| 242 { | |
| 243 buf[bpos] = sign; | |
| 244 } | |
| 245 else bpos--; | |
| 246 | |
| 247 /* Now write it out in correct order. */ | |
| 248 while( bpos >= 0 ) | |
| 249 *s++ = buf[bpos--]; | |
| 250 | |
| 251 *s = 0; | |
| 252 | |
| 253 return s; | |
| 254 } | |
| 255 | |
| 256 static char *dbg_adddec(char *s, int x) | |
| 257 { | |
| 258 return dbg_addint(s, x, 10); | |
| 259 } | |
| 260 | |
| 261 //-------------------------------------------------------------------------- | |
| 262 | |
| 263 externC int dbg_threadinfo( | |
| 2 | 264 threadref * threadid, |
| 265 struct cygmon_thread_debug_info * info) | |
| 0 | 266 { |
| 267 static char statebuf[60]; | |
| 268 | |
| 269 Cyg_Thread *thread = dbg_get_thread(threadid); | |
| 270 if( thread == 0 ) return 0; | |
| 271 | |
| 272 info->context_exists = 1; | |
| 273 | |
| 274 char *sbp = statebuf; | |
| 275 char *s; | |
| 276 | |
| 277 if( thread->get_state() & Cyg_Thread::SUSPENDED ) | |
| 278 { | |
| 279 sbp = dbg_addstr( sbp, "suspended+"); | |
| 280 } | |
| 281 | |
| 282 switch( thread->get_state() & ~Cyg_Thread::SUSPENDED ) | |
| 283 { | |
| 284 case Cyg_Thread::RUNNING: | |
|
14
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
285 if ( Cyg_Scheduler::get_current_thread() == thread ) { |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
286 s = "running"; break; |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
287 } |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
288 else if ( thread->get_state() & Cyg_Thread::SUSPENDED ) { |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
289 s = ""; sbp--; /*kill '+'*/ break; |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
290 } |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
291 else { |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
292 s = "ready"; break; |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
293 } |
| 0 | 294 case Cyg_Thread::SLEEPING: |
| 295 s = "sleeping"; break; | |
|
14
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
296 case Cyg_Thread::COUNTSLEEP | Cyg_Thread::SLEEPING: |
| 0 | 297 case Cyg_Thread::COUNTSLEEP: |
| 298 s = "counted sleep"; break; | |
| 299 case Cyg_Thread::CREATING: | |
|
14
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
300 s = "creating"; sbp = statebuf; break; |
| 0 | 301 case Cyg_Thread::EXITED: |
|
14
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
302 s = "exited"; sbp = statebuf; break; |
| 0 | 303 default: |
| 304 s = "unknown state"; break; | |
| 305 } | |
| 306 | |
| 307 sbp = dbg_addstr( sbp, s ); | |
| 308 sbp = dbg_addstr( sbp, ", Priority: " ); | |
| 309 sbp = dbg_adddec( sbp, thread->get_priority() ); | |
| 310 | |
| 311 info->thread_display = statebuf; | |
| 312 | |
| 313 #ifdef CYGVAR_KERNEL_THREADS_NAME | |
| 314 info->unique_thread_name = thread->get_name(); | |
| 315 #else | |
| 316 info->unique_thread_name = 0; | |
| 317 #endif | |
| 318 | |
| 319 info->more_display = 0; | |
| 320 | |
| 321 return 1 ; | |
| 322 } | |
| 323 | |
| 324 //-------------------------------------------------------------------------- | |
| 325 | |
| 326 externC int dbg_getthreadreg( | |
| 2 | 327 threadref * osthreadid, |
| 328 int regcount, /* count of registers in the array */ | |
| 329 void * regval) /* fillin this array */ | |
| 0 | 330 { |
| 331 Cyg_Thread *thread = dbg_get_thread(osthreadid); | |
| 332 | |
| 333 if( thread == 0 ) return 0; | |
| 334 | |
| 335 if( thread == Cyg_Scheduler::get_current_thread() ) | |
| 336 { | |
| 337 #if defined(CYG_HAL_USE_ROM_MONITOR_CYGMON) | |
| 338 // We have no state for the current thread, Cygmon has | |
| 339 // got that and we cannot get at it. | |
| 340 return 0; | |
| 341 #elif defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS) | |
| 2 | 342 // registers hold the state of the current thread. |
| 343 __stub_copy_registers ((target_register_t *)regval, registers); | |
| 0 | 344 #else |
| 345 return 0; | |
| 346 #endif | |
| 347 } | |
| 348 else | |
| 349 { | |
| 350 HAL_SavedRegisters *regs = thread->get_saved_context(); | |
| 351 if( regs == 0 ) return 0; | |
| 352 | |
| 353 HAL_GET_GDB_REGISTERS (regval, regs); | |
| 354 } | |
| 355 | |
| 356 return 1 ; | |
| 357 } | |
| 358 | |
| 359 //-------------------------------------------------------------------------- | |
| 2 | 360 |
| 0 | 361 externC int dbg_setthreadreg( |
| 2 | 362 threadref * osthreadid, |
| 363 int regcount , /* number of registers */ | |
| 364 void * regval) | |
| 0 | 365 { |
| 366 Cyg_Thread *thread = dbg_get_thread(osthreadid); | |
| 367 | |
| 368 if( thread == 0 ) return 0; | |
| 369 | |
| 370 if( thread == Cyg_Scheduler::get_current_thread() ) | |
| 371 { | |
| 372 #if defined(CYG_HAL_USE_ROM_MONITOR_CYGMON) | |
| 373 // We have no state for the current thread, Cygmon has | |
| 374 // got that and we cannot get at it. | |
| 375 return 0; | |
| 376 #elif defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS) | |
| 2 | 377 // registers hold the state of the current thread. |
| 378 __stub_copy_registers (registers, (target_register_t *)regval); | |
| 0 | 379 #else |
| 380 return 0; | |
| 381 #endif | |
| 382 } | |
| 383 else | |
| 384 { | |
| 385 HAL_SavedRegisters *regs = thread->get_saved_context(); | |
| 386 if( regs == 0 ) return 0; | |
| 387 | |
| 388 HAL_SET_GDB_REGISTERS (regs, regval); | |
| 389 } | |
| 390 | |
| 391 return 1; | |
| 392 } | |
| 393 | |
| 2 | 394 //-------------------------------------------------------------------------- |
| 395 // Thread scheduler control for debugger. | |
| 396 // Arguments: | |
| 397 // osthreadid : must match currently executing thread. | |
| 398 // Future use: change the currently executing thread. | |
| 399 // lock : 0 == unlock scheduler, 1 == lock scheduler | |
| 400 // mode : 0 == single-instruction step, 1 == free running | |
| 401 // | |
| 402 // Return values: | |
| 403 // 1 == success | |
| 404 // 0 == failure | |
| 405 // -1 == request that the caller handle this itself | |
| 406 // (eg.by disabling interrupts) | |
| 407 // | |
| 408 | |
| 409 externC int dbg_scheduler( | |
| 410 threadref * osthreadid, | |
| 411 int lock, /* 0 == unlock, 1 == lock */ | |
| 412 int mode) /* 0 == step, 1 == continue */ | |
| 413 { | |
| 414 #if 0 | |
| 415 /* Minimal implementation: let stub do the work. */ | |
| 416 return -1; // Stub will disable interrupts | |
| 417 #else | |
| 418 Cyg_Thread *thread = dbg_get_thread(osthreadid); | |
| 419 | |
| 420 if( thread == 0 ) return 0; // fail | |
| 421 | |
| 422 if( thread == Cyg_Scheduler::get_current_thread() ) | |
| 423 { | |
| 424 // OK to proceed | |
| 425 | |
| 426 if (lock) | |
| 427 { | |
| 428 Cyg_Scheduler::lock(); | |
| 429 } | |
| 430 else | |
| 431 { | |
| 432 if (Cyg_Scheduler::get_sched_lock() >= 1) | |
| 433 Cyg_Scheduler::unlock_simple(); | |
| 434 } | |
| 435 return 1; // success | |
| 436 } | |
| 437 else | |
| 438 { | |
| 439 // Cannot accept any thread other than current one | |
| 440 return 0; // fail | |
| 441 } | |
| 442 #endif | |
| 443 } | |
| 444 | |
| 445 | |
| 0 | 446 #endif // CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT |
| 447 | |
| 448 //-------------------------------------------------------------------------- | |
| 449 // End of dbg_gdb.cxx |
