Mercurial > nand-ecoscentric
annotate packages/kernel/current/src/debug/dbg_gdb.cxx @ 14:01ce82f3e11a ecos-sw-1999-06-11
Merge from eCos master repository on 1999-06-11-17:05:41-BST
| author | jlarmour |
|---|---|
| date | Fri, 11 Jun 1999 09:36:56 +0000 |
| parents | d3fbcdfa1b2f |
| children | 641b639be825 |
| 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 { | |
|
10
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
102 if( thread == NULL ) |
|
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
103 { |
|
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
104 ((unsigned long *)ref)[0] = 0; |
|
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
105 ((unsigned long *)ref)[1] = 0; |
|
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
106 } |
|
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
107 else |
|
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 cyg_uint16 id = thread->get_unique_id(); |
| 0 | 110 |
| 111 #if USE_ID | |
|
10
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
112 ((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
|
113 ((unsigned long *)ref)[1] = (unsigned long)swap32(id); |
| 0 | 114 #else |
|
10
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
115 ((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
|
116 ((unsigned long *)ref)[0] = (unsigned long)id; |
| 0 | 117 #endif |
|
10
d3fbcdfa1b2f
Merge from eCos master repository on 1999-05-29-00:13:11-BST
jlarmour
parents:
2
diff
changeset
|
118 } |
| 0 | 119 } |
| 120 | |
| 121 static Cyg_Thread *dbg_get_thread( threadref *ref) | |
| 122 { | |
| 123 #if USE_ID | |
| 124 | |
| 125 cyg_uint16 id = 0; | |
| 126 | |
| 127 id = (cyg_uint16)swap32(((unsigned long *)ref)[1]); | |
| 128 | |
| 129 Cyg_Thread *th = Cyg_Thread::get_list_head(); | |
| 130 while( th != 0 ) | |
| 131 { | |
| 132 if( th->get_unique_id() == id ) break; | |
| 133 th = th->get_list_next(); | |
| 134 } | |
| 135 | |
| 136 // if( thread->get_unique_id() != id ) th = 0; | |
| 137 | |
| 138 #else | |
| 139 | |
| 140 cyg_uint16 id = 0; | |
| 141 | |
| 142 Cyg_Thread *thread = (Cyg_Thread *)(((unsigned long *)ref)[1]); | |
| 143 id = (cyg_uint16)(((unsigned long *)ref)[0]); | |
| 144 | |
| 145 // Validate the thread. | |
| 146 Cyg_Thread *th = Cyg_Thread::get_list_head(); | |
| 147 while( th != 0 ) | |
| 148 { | |
| 149 if( th == thread ) break; | |
| 150 th = th->get_list_next(); | |
| 151 } | |
| 152 | |
| 153 // if( thread->get_unique_id() != id ) th = 0; | |
| 154 | |
| 155 #endif | |
| 156 | |
| 157 return th; | |
| 158 } | |
| 159 | |
| 160 //-------------------------------------------------------------------------- | |
| 161 | |
| 162 externC int dbg_currthread(threadref * varparm) | |
| 163 { | |
| 164 Cyg_Thread *thread = Cyg_Scheduler::get_current_thread(); | |
| 165 | |
| 166 dbg_make_threadref(thread, varparm ); | |
| 167 | |
| 168 return 1 ; | |
| 169 } | |
| 170 | |
| 171 //-------------------------------------------------------------------------- | |
| 172 | |
| 173 externC int dbg_currthread_id(void) | |
| 174 { | |
| 175 Cyg_Thread *thread = Cyg_Scheduler::get_current_thread(); | |
| 176 return thread->get_unique_id (); | |
| 177 } | |
| 178 | |
| 179 //-------------------------------------------------------------------------- | |
| 180 | |
| 181 externC int dbg_threadlist(int startflag, | |
| 2 | 182 threadref * lastthreadid, |
| 183 threadref * next_thread) | |
| 0 | 184 { |
| 185 Cyg_Thread *thread; | |
| 186 if( startflag ) | |
| 187 { | |
| 188 thread = Cyg_Thread::get_list_head(); | |
| 189 dbg_make_threadref(thread, next_thread); | |
| 190 } | |
| 191 else | |
| 192 { | |
| 193 thread = dbg_get_thread(lastthreadid); | |
| 194 | |
| 195 if( thread == 0 ) return 0; | |
| 196 thread = thread->get_list_next(); | |
| 197 | |
| 198 if( thread == 0 ) return 0; | |
| 199 dbg_make_threadref(thread, next_thread); | |
| 200 } | |
| 201 return 1 ; | |
| 202 } | |
| 203 | |
| 204 //-------------------------------------------------------------------------- | |
| 205 // Some support routines for manufacturing thread info strings | |
| 206 | |
| 207 static char *dbg_addstr(char *s, char *t) | |
| 208 { | |
| 209 while( (*s++ = *t++) != 0 ); | |
| 210 | |
| 211 return s-1; | |
| 212 } | |
| 213 | |
| 214 static char *dbg_addint(char *s, int n, int base) | |
| 215 { | |
| 216 char buf[16]; | |
| 217 char sign = '+'; | |
| 218 cyg_count8 bpos; | |
| 219 char *digits = "0123456789ABCDEF"; | |
| 220 | |
| 221 if( n < 0 ) n = -n, sign = '-'; | |
| 222 | |
| 223 /* Set pos to start */ | |
| 224 bpos = 0; | |
| 225 | |
| 226 /* construct digits into buffer in reverse order */ | |
| 227 if( n == 0 ) buf[bpos++] = '0'; | |
| 228 else while( n != 0 ) | |
| 229 { | |
| 230 cyg_ucount8 d = n % base; | |
| 231 buf[bpos++] = digits[d]; | |
| 232 n /= base; | |
| 233 } | |
| 234 | |
| 235 /* set sign if negative. */ | |
| 236 if( sign == '-' ) | |
| 237 { | |
| 238 buf[bpos] = sign; | |
| 239 } | |
| 240 else bpos--; | |
| 241 | |
| 242 /* Now write it out in correct order. */ | |
| 243 while( bpos >= 0 ) | |
| 244 *s++ = buf[bpos--]; | |
| 245 | |
| 246 *s = 0; | |
| 247 | |
| 248 return s; | |
| 249 } | |
| 250 | |
| 251 static char *dbg_adddec(char *s, int x) | |
| 252 { | |
| 253 return dbg_addint(s, x, 10); | |
| 254 } | |
| 255 | |
| 256 //-------------------------------------------------------------------------- | |
| 257 | |
| 258 externC int dbg_threadinfo( | |
| 2 | 259 threadref * threadid, |
| 260 struct cygmon_thread_debug_info * info) | |
| 0 | 261 { |
| 262 static char statebuf[60]; | |
| 263 | |
| 264 Cyg_Thread *thread = dbg_get_thread(threadid); | |
| 265 if( thread == 0 ) return 0; | |
| 266 | |
| 267 info->context_exists = 1; | |
| 268 | |
| 269 char *sbp = statebuf; | |
| 270 char *s; | |
| 271 | |
| 272 if( thread->get_state() & Cyg_Thread::SUSPENDED ) | |
| 273 { | |
| 274 sbp = dbg_addstr( sbp, "suspended+"); | |
| 275 } | |
| 276 | |
| 277 switch( thread->get_state() & ~Cyg_Thread::SUSPENDED ) | |
| 278 { | |
| 279 case Cyg_Thread::RUNNING: | |
|
14
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
280 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
|
281 s = "running"; break; |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
282 } |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
283 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
|
284 s = ""; sbp--; /*kill '+'*/ break; |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
285 } |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
286 else { |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
287 s = "ready"; break; |
|
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
288 } |
| 0 | 289 case Cyg_Thread::SLEEPING: |
| 290 s = "sleeping"; break; | |
|
14
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
291 case Cyg_Thread::COUNTSLEEP | Cyg_Thread::SLEEPING: |
| 0 | 292 case Cyg_Thread::COUNTSLEEP: |
| 293 s = "counted sleep"; break; | |
| 294 case Cyg_Thread::CREATING: | |
|
14
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
295 s = "creating"; sbp = statebuf; break; |
| 0 | 296 case Cyg_Thread::EXITED: |
|
14
01ce82f3e11a
Merge from eCos master repository on 1999-06-11-17:05:41-BST
jlarmour
parents:
10
diff
changeset
|
297 s = "exited"; sbp = statebuf; break; |
| 0 | 298 default: |
| 299 s = "unknown state"; break; | |
| 300 } | |
| 301 | |
| 302 sbp = dbg_addstr( sbp, s ); | |
| 303 sbp = dbg_addstr( sbp, ", Priority: " ); | |
| 304 sbp = dbg_adddec( sbp, thread->get_priority() ); | |
| 305 | |
| 306 info->thread_display = statebuf; | |
| 307 | |
| 308 #ifdef CYGVAR_KERNEL_THREADS_NAME | |
| 309 info->unique_thread_name = thread->get_name(); | |
| 310 #else | |
| 311 info->unique_thread_name = 0; | |
| 312 #endif | |
| 313 | |
| 314 info->more_display = 0; | |
| 315 | |
| 316 return 1 ; | |
| 317 } | |
| 318 | |
| 319 //-------------------------------------------------------------------------- | |
| 320 | |
| 321 externC int dbg_getthreadreg( | |
| 2 | 322 threadref * osthreadid, |
| 323 int regcount, /* count of registers in the array */ | |
| 324 void * regval) /* fillin this array */ | |
| 0 | 325 { |
| 326 Cyg_Thread *thread = dbg_get_thread(osthreadid); | |
| 327 | |
| 328 if( thread == 0 ) return 0; | |
| 329 | |
| 330 if( thread == Cyg_Scheduler::get_current_thread() ) | |
| 331 { | |
| 332 #if defined(CYG_HAL_USE_ROM_MONITOR_CYGMON) | |
| 333 // We have no state for the current thread, Cygmon has | |
| 334 // got that and we cannot get at it. | |
| 335 return 0; | |
| 336 #elif defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS) | |
| 2 | 337 // registers hold the state of the current thread. |
| 338 __stub_copy_registers ((target_register_t *)regval, registers); | |
| 0 | 339 #else |
| 340 return 0; | |
| 341 #endif | |
| 342 } | |
| 343 else | |
| 344 { | |
| 345 HAL_SavedRegisters *regs = thread->get_saved_context(); | |
| 346 if( regs == 0 ) return 0; | |
| 347 | |
| 348 HAL_GET_GDB_REGISTERS (regval, regs); | |
| 349 } | |
| 350 | |
| 351 return 1 ; | |
| 352 } | |
| 353 | |
| 354 //-------------------------------------------------------------------------- | |
| 2 | 355 |
| 0 | 356 externC int dbg_setthreadreg( |
| 2 | 357 threadref * osthreadid, |
| 358 int regcount , /* number of registers */ | |
| 359 void * regval) | |
| 0 | 360 { |
| 361 Cyg_Thread *thread = dbg_get_thread(osthreadid); | |
| 362 | |
| 363 if( thread == 0 ) return 0; | |
| 364 | |
| 365 if( thread == Cyg_Scheduler::get_current_thread() ) | |
| 366 { | |
| 367 #if defined(CYG_HAL_USE_ROM_MONITOR_CYGMON) | |
| 368 // We have no state for the current thread, Cygmon has | |
| 369 // got that and we cannot get at it. | |
| 370 return 0; | |
| 371 #elif defined(CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS) | |
| 2 | 372 // registers hold the state of the current thread. |
| 373 __stub_copy_registers (registers, (target_register_t *)regval); | |
| 0 | 374 #else |
| 375 return 0; | |
| 376 #endif | |
| 377 } | |
| 378 else | |
| 379 { | |
| 380 HAL_SavedRegisters *regs = thread->get_saved_context(); | |
| 381 if( regs == 0 ) return 0; | |
| 382 | |
| 383 HAL_SET_GDB_REGISTERS (regs, regval); | |
| 384 } | |
| 385 | |
| 386 return 1; | |
| 387 } | |
| 388 | |
| 2 | 389 //-------------------------------------------------------------------------- |
| 390 // Thread scheduler control for debugger. | |
| 391 // Arguments: | |
| 392 // osthreadid : must match currently executing thread. | |
| 393 // Future use: change the currently executing thread. | |
| 394 // lock : 0 == unlock scheduler, 1 == lock scheduler | |
| 395 // mode : 0 == single-instruction step, 1 == free running | |
| 396 // | |
| 397 // Return values: | |
| 398 // 1 == success | |
| 399 // 0 == failure | |
| 400 // -1 == request that the caller handle this itself | |
| 401 // (eg.by disabling interrupts) | |
| 402 // | |
| 403 | |
| 404 externC int dbg_scheduler( | |
| 405 threadref * osthreadid, | |
| 406 int lock, /* 0 == unlock, 1 == lock */ | |
| 407 int mode) /* 0 == step, 1 == continue */ | |
| 408 { | |
| 409 #if 0 | |
| 410 /* Minimal implementation: let stub do the work. */ | |
| 411 return -1; // Stub will disable interrupts | |
| 412 #else | |
| 413 Cyg_Thread *thread = dbg_get_thread(osthreadid); | |
| 414 | |
| 415 if( thread == 0 ) return 0; // fail | |
| 416 | |
| 417 if( thread == Cyg_Scheduler::get_current_thread() ) | |
| 418 { | |
| 419 // OK to proceed | |
| 420 | |
| 421 if (lock) | |
| 422 { | |
| 423 Cyg_Scheduler::lock(); | |
| 424 } | |
| 425 else | |
| 426 { | |
| 427 if (Cyg_Scheduler::get_sched_lock() >= 1) | |
| 428 Cyg_Scheduler::unlock_simple(); | |
| 429 } | |
| 430 return 1; // success | |
| 431 } | |
| 432 else | |
| 433 { | |
| 434 // Cannot accept any thread other than current one | |
| 435 return 0; // fail | |
| 436 } | |
| 437 #endif | |
| 438 } | |
| 439 | |
| 440 | |
| 0 | 441 #endif // CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT |
| 442 | |
| 443 //-------------------------------------------------------------------------- | |
| 444 // End of dbg_gdb.cxx |
