Tue Jul 15 17:35:39 2014 UTC ()
replace the old macros with the function names like the rest of the code did.


(christos)
diff -r1.19 -r1.20 src/external/gpl3/gdb/dist/gdb/nbsd-thread.c

cvs diff -r1.19 -r1.20 src/external/gpl3/gdb/dist/gdb/Attic/nbsd-thread.c (expand / switch to unified diff)

--- src/external/gpl3/gdb/dist/gdb/Attic/nbsd-thread.c 2014/06/22 23:52:58 1.19
+++ src/external/gpl3/gdb/dist/gdb/Attic/nbsd-thread.c 2014/07/15 17:35:39 1.20
@@ -73,32 +73,26 @@ static int nbsd_thread_active = 0; @@ -73,32 +73,26 @@ static int nbsd_thread_active = 0;
73static int nbsd_thread_core = 0; 73static int nbsd_thread_core = 0;
74 74
75static ptid_t main_ptid; /* Real process ID */ 75static ptid_t main_ptid; /* Real process ID */
76 76
77static ptid_t cached_thread; 77static ptid_t cached_thread;
78 78
79struct target_ops nbsd_thread_ops; 79struct target_ops nbsd_thread_ops;
80 80
81struct td_proc_callbacks_t nbsd_thread_callbacks; 81struct td_proc_callbacks_t nbsd_thread_callbacks;
82 82
83static ptid_t find_active_thread (void); 83static ptid_t find_active_thread (void);
84static void nbsd_find_new_threads (struct target_ops *); 84static void nbsd_find_new_threads (struct target_ops *);
85 85
86#define GET_PID(ptid) ptid_get_pid (ptid) 
87#define GET_LWP(ptid) ptid_get_lwp (ptid) 
88 
89#define IS_LWP(ptid) (GET_LWP (ptid) != 0) 
90 
91#define BUILD_LWP(lwp, ptid) ptid_build (GET_PID(ptid), (lwp), 0) 
92 86
93static td_proc_t *main_ta; 87static td_proc_t *main_ta;
94 88
95struct nbsd_thread_proc_arg { 89struct nbsd_thread_proc_arg {
96 struct target_ops *ops; 90 struct target_ops *ops;
97 struct regcache *cache; 91 struct regcache *cache;
98} main_arg; 92} main_arg;
99 93
100static const char *syncnames[] = { 94static const char *syncnames[] = {
101 "unknown", "mutex", "cond var", "spinlock", "thread" 95 "unknown", "mutex", "cond var", "spinlock", "thread"
102}; 96};
103 97
104struct string_map 98struct string_map
@@ -133,27 +127,28 @@ td_err_string (int errcode) @@ -133,27 +127,28 @@ td_err_string (int errcode)
133 return td_err_table[i].str; 127 return td_err_table[i].str;
134 128
135 sprintf (buf, "Unknown thread_db error code: %d", errcode); 129 sprintf (buf, "Unknown thread_db error code: %d", errcode);
136 130
137 return buf; 131 return buf;
138} 132}
139 133
140static void 134static void
141nbsd_thread_activate (void) 135nbsd_thread_activate (void)
142{ 136{
143 nbsd_thread_active = 1; 137 nbsd_thread_active = 1;
144 main_ptid = inferior_ptid; 138 main_ptid = inferior_ptid;
145 cached_thread = minus_one_ptid; 139 cached_thread = minus_one_ptid;
146 thread_change_ptid(inferior_ptid, BUILD_LWP(1, inferior_ptid)); 140 thread_change_ptid(inferior_ptid,
 141 ptid_build (ptid_get_pid (inferior_ptid), 1, 0));
147 nbsd_find_new_threads (NULL); 142 nbsd_find_new_threads (NULL);
148 inferior_ptid = find_active_thread (); 143 inferior_ptid = find_active_thread ();
149} 144}
150 145
151static void 146static void
152nbsd_thread_deactivate (void) 147nbsd_thread_deactivate (void)
153{ 148{
154 td_close (main_ta); 149 td_close (main_ta);
155 150
156 inferior_ptid = main_ptid; 151 inferior_ptid = main_ptid;
157 main_ptid = minus_one_ptid; 152 main_ptid = minus_one_ptid;
158 cached_thread = main_ptid; 153 cached_thread = main_ptid;
159 nbsd_thread_active = 0; 154 nbsd_thread_active = 0;
@@ -270,40 +265,41 @@ static ptid_t @@ -270,40 +265,41 @@ static ptid_t
270find_active_thread (void) 265find_active_thread (void)
271{ 266{
272 int val; 267 int val;
273 td_thread_t *thread; 268 td_thread_t *thread;
274 td_thread_info_t ti; 269 td_thread_info_t ti;
275 struct ptrace_lwpinfo pl; 270 struct ptrace_lwpinfo pl;
276 271
277 if (!ptid_equal (cached_thread, minus_one_ptid)) 272 if (!ptid_equal (cached_thread, minus_one_ptid))
278 return cached_thread; 273 return cached_thread;
279 274
280 if (target_has_execution) 275 if (target_has_execution)
281 { 276 {
282 pl.pl_lwpid = 0; 277 pl.pl_lwpid = 0;
283 val = ptrace (PT_LWPINFO, GET_PID(inferior_ptid), (void *)&pl, sizeof(pl)); 278 val = ptrace (PT_LWPINFO, ptid_get_pid(inferior_ptid), (void *)&pl, sizeof(pl));
284 while ((val != -1) && (pl.pl_lwpid != 0) && 279 while ((val != -1) && (pl.pl_lwpid != 0) &&
285 (pl.pl_event != PL_EVENT_SIGNAL)) 280 (pl.pl_event != PL_EVENT_SIGNAL)) {
286 val = ptrace (PT_LWPINFO, GET_PID(inferior_ptid), (void *)&pl, sizeof(pl)); 281 val = ptrace (PT_LWPINFO, ptid_get_pid(inferior_ptid), (void *)&pl, sizeof(pl));
 282 }
287 if (pl.pl_lwpid == 0) 283 if (pl.pl_lwpid == 0)
288 /* found no "active" thread, stay with current */ 284 /* found no "active" thread, stay with current */
289 pl.pl_lwpid = inferior_ptid.lwp; 285 pl.pl_lwpid = inferior_ptid.lwp;
290 } 286 }
291 else 287 else
292 { 288 {
293 return inferior_ptid; 289 return inferior_ptid;
294 } 290 }
295 291
296 cached_thread = BUILD_LWP (pl.pl_lwpid, main_ptid); 292 cached_thread = ptid_build (ptid_get_pid (main_ptid), pl.pl_lwpid, 0);
297 return cached_thread; 293 return cached_thread;
298} 294}
299 295
300 296
301/* Wait for any threads to stop. We may have to convert PID from a thread id 297/* Wait for any threads to stop. We may have to convert PID from a thread id
302 to a LWP id, and vice versa on the way out. */ 298 to a LWP id, and vice versa on the way out. */
303 299
304static ptid_t 300static ptid_t
305nbsd_thread_wait (struct target_ops *ops, ptid_t ptid, 301nbsd_thread_wait (struct target_ops *ops, ptid_t ptid,
306 struct target_waitstatus *ourstatus, int options) 302 struct target_waitstatus *ourstatus, int options)
307{ 303{
308 ptid_t rtnval; 304 ptid_t rtnval;
309 struct target_ops *beneath = find_target_beneath (ops); 305 struct target_ops *beneath = find_target_beneath (ops);
@@ -331,28 +327,28 @@ nbsd_thread_fetch_registers (struct targ @@ -331,28 +327,28 @@ nbsd_thread_fetch_registers (struct targ
331 struct target_ops *beneath = find_target_beneath (ops); 327 struct target_ops *beneath = find_target_beneath (ops);
332 td_thread_t *thread; 328 td_thread_t *thread;
333 gregset_t gregs; 329 gregset_t gregs;
334#ifdef HAVE_FPREGS 330#ifdef HAVE_FPREGS
335 fpregset_t fpregs; 331 fpregset_t fpregs;
336#endif 332#endif
337 int val; 333 int val;
338 struct cleanup *old_chain; 334 struct cleanup *old_chain;
339 335
340 old_chain = save_inferior_ptid (); 336 old_chain = save_inferior_ptid ();
341 337
342 if (!target_has_execution) 338 if (!target_has_execution)
343 { 339 {
344 inferior_ptid = pid_to_ptid ((GET_LWP (inferior_ptid) << 16) |  340 inferior_ptid = pid_to_ptid ((ptid_get_lwp (inferior_ptid) << 16) |
345 GET_PID (inferior_ptid)); 341 ptid_get_pid (inferior_ptid));
346 } 342 }
347 beneath->to_fetch_registers (beneath, cache, regno); 343 beneath->to_fetch_registers (beneath, cache, regno);
348  344
349 do_cleanups (old_chain); 345 do_cleanups (old_chain);
350} 346}
351 347
352static void 348static void
353nbsd_thread_store_registers (struct target_ops *ops, struct regcache *cache, 349nbsd_thread_store_registers (struct target_ops *ops, struct regcache *cache,
354 int regno) 350 int regno)
355{ 351{
356 struct target_ops *beneath = find_target_beneath (ops); 352 struct target_ops *beneath = find_target_beneath (ops);
357 td_thread_t *thread; 353 td_thread_t *thread;
358 gregset_t gregs; 354 gregset_t gregs;
@@ -408,49 +404,49 @@ nbsd_core_files_info (struct target_ops  @@ -408,49 +404,49 @@ nbsd_core_files_info (struct target_ops
408 struct target_ops *beneath = find_target_beneath (ignore); 404 struct target_ops *beneath = find_target_beneath (ignore);
409 beneath->to_files_info (beneath); 405 beneath->to_files_info (beneath);
410} 406}
411 407
412/* Convert a ptid to printable form. */ 408/* Convert a ptid to printable form. */
413 409
414static char * 410static char *
415nbsd_pid_to_str (struct target_ops *ops, ptid_t ptid) 411nbsd_pid_to_str (struct target_ops *ops, ptid_t ptid)
416{ 412{
417 static char buf[100]; 413 static char buf[100];
418 td_thread_t *th; 414 td_thread_t *th;
419 char name[32]; 415 char name[32];
420 416
421 if ((GET_LWP(ptid) == 0) &&  417 if ((ptid_get_lwp(ptid) == 0) &&
422 (nbsd_thread_active == 0)) 418 (nbsd_thread_active == 0))
423 sprintf (buf, "process %d", GET_PID (ptid)); 419 sprintf (buf, "process %d", ptid_get_pid (ptid));
424 else 420 else
425 sprintf (buf, "LWP %ld", GET_LWP (ptid)); 421 sprintf (buf, "LWP %ld", ptid_get_lwp (ptid));
426 422
427 return buf; 423 return buf;
428} 424}
429 425
430 426
431#ifdef notdef 427#ifdef notdef
432static void 428static void
433nbsd_add_to_thread_list (bfd *abfd, asection *asect, PTR reg_sect_arg) 429nbsd_add_to_thread_list (bfd *abfd, asection *asect, PTR reg_sect_arg)
434{ 430{
435 int regval; 431 int regval;
436 td_thread_t *dummy; 432 td_thread_t *dummy;
437 433
438 if (strncmp (bfd_section_name (abfd, asect), ".reg/", 5) != 0) 434 if (strncmp (bfd_section_name (abfd, asect), ".reg/", 5) != 0)
439 return; 435 return;
440 436
441 regval = atoi (bfd_section_name (abfd, asect) + 5); 437 regval = atoi (bfd_section_name (abfd, asect) + 5);
442 438
443 add_thread (BUILD_LWP(regval, main_ptid)); 439 add_thread (ptid_build (ptid_get_pid (main_ptid), regval, 0));
444} 440}
445#endif 441#endif
446 442
447/* This routine is called whenever a new symbol table is read in, or when all 443/* This routine is called whenever a new symbol table is read in, or when all
448 symbol tables are removed. libthread_db can only be initialized when it 444 symbol tables are removed. libthread_db can only be initialized when it
449 finds the right variables in libthread.so. Since it's a shared library, 445 finds the right variables in libthread.so. Since it's a shared library,
450 those variables don't show up until the library gets mapped and the symbol 446 those variables don't show up until the library gets mapped and the symbol
451 table is read in. */ 447 table is read in. */
452 448
453/* This new_objfile event is now managed by a chained function pointer. 449/* This new_objfile event is now managed by a chained function pointer.
454 * It is the callee's responsability to call the next client on the chain. 450 * It is the callee's responsability to call the next client on the chain.
455 */ 451 */
456 452
@@ -495,31 +491,31 @@ quit: @@ -495,31 +491,31 @@ quit:
495 return; 491 return;
496} 492}
497 493
498static int 494static int
499nbsd_thread_alive (struct target_ops *ops, ptid_t ptid) 495nbsd_thread_alive (struct target_ops *ops, ptid_t ptid)
500{ 496{
501 struct target_ops *beneath = find_target_beneath (ops); 497 struct target_ops *beneath = find_target_beneath (ops);
502 td_thread_t *th; 498 td_thread_t *th;
503 td_thread_info_t ti; 499 td_thread_info_t ti;
504 int val; 500 int val;
505 501
506 if (nbsd_thread_active) 502 if (nbsd_thread_active)
507 { 503 {
508 if (IS_LWP (ptid)) 504 if (ptid_lwp_p (ptid))
509 { 505 {
510 struct ptrace_lwpinfo pl; 506 struct ptrace_lwpinfo pl;
511 pl.pl_lwpid = GET_LWP (ptid); 507 pl.pl_lwpid = ptid_get_lwp (ptid);
512 val = ptrace (PT_LWPINFO, GET_PID (ptid), (void *)&pl, sizeof(pl)); 508 val = ptrace (PT_LWPINFO, ptid_get_pid (ptid), (void *)&pl, sizeof(pl));
513 if (val == -1) 509 if (val == -1)
514 val = 0; 510 val = 0;
515 else 511 else
516 val = 1; 512 val = 1;
517 } 513 }
518 else 514 else
519 val = beneath->to_thread_alive (beneath, ptid); 515 val = beneath->to_thread_alive (beneath, ptid);
520 } 516 }
521 else 517 else
522 val = beneath->to_thread_alive (beneath, ptid); 518 val = beneath->to_thread_alive (beneath, ptid);
523 519
524 return val; 520 return val;
525} 521}
@@ -543,33 +539,33 @@ nbsd_find_new_threads (struct target_ops @@ -543,33 +539,33 @@ nbsd_find_new_threads (struct target_ops
543 if (nbsd_thread_active == 0) 539 if (nbsd_thread_active == 0)
544 return; 540 return;
545 541
546 if (ptid_equal (inferior_ptid, minus_one_ptid)) 542 if (ptid_equal (inferior_ptid, minus_one_ptid))
547 { 543 {
548 printf_filtered ("No process.\n"); 544 printf_filtered ("No process.\n");
549 return; 545 return;
550 } 546 }
551 547
552 if (target_has_execution) 548 if (target_has_execution)
553 { 549 {
554 struct ptrace_lwpinfo pl; 550 struct ptrace_lwpinfo pl;
555 pl.pl_lwpid = 0; 551 pl.pl_lwpid = 0;
556 retval = ptrace (PT_LWPINFO, GET_PID(inferior_ptid), (void *)&pl, sizeof(pl)); 552 retval = ptrace (PT_LWPINFO, ptid_get_pid(inferior_ptid), (void *)&pl, sizeof(pl));
557 while ((retval != -1) && pl.pl_lwpid != 0) 553 while ((retval != -1) && pl.pl_lwpid != 0)
558 { 554 {
559 ptid = BUILD_LWP (pl.pl_lwpid, main_ptid); 555 ptid = ptid_build (ptid_get_pid (main_ptid), pl.pl_lwpid, 0);
560 if (!in_thread_list (ptid)) 556 if (!in_thread_list (ptid))
561 add_thread (ptid); 557 add_thread (ptid);
562 retval = ptrace (PT_LWPINFO, GET_PID(inferior_ptid), (void *)&pl, sizeof(pl)); 558 retval = ptrace (PT_LWPINFO, ptid_get_pid(inferior_ptid), (void *)&pl, sizeof(pl));
563 } 559 }
564 } 560 }
565} 561}
566 562
567 563
568/* Fork an inferior process, and start debugging it. */ 564/* Fork an inferior process, and start debugging it. */
569 565
570static void 566static void
571nbsd_thread_create_inferior (struct target_ops *ops, char *exec_file, 567nbsd_thread_create_inferior (struct target_ops *ops, char *exec_file,
572 char *allargs, char **env, int from_tty) 568 char *allargs, char **env, int from_tty)
573{ 569{
574 struct target_ops *beneath = find_target_beneath (ops); 570 struct target_ops *beneath = find_target_beneath (ops);
575 nbsd_thread_core = 0; 571 nbsd_thread_core = 0;
@@ -658,35 +654,35 @@ nbsd_thread_proc_getregs (void *arg, int @@ -658,35 +654,35 @@ nbsd_thread_proc_getregs (void *arg, int
658 struct nbsd_thread_proc_arg *a = arg;  654 struct nbsd_thread_proc_arg *a = arg;
659 struct regcache *cache = a->cache; 655 struct regcache *cache = a->cache;
660 struct target_ops *ops = a->ops; 656 struct target_ops *ops = a->ops;
661 struct cleanup *old_chain; 657 struct cleanup *old_chain;
662 struct target_ops *beneath = find_target_beneath (ops); 658 struct target_ops *beneath = find_target_beneath (ops);
663 int ret; 659 int ret;
664 660
665 old_chain = save_inferior_ptid (); 661 old_chain = save_inferior_ptid ();
666 662
667 if (target_has_execution) 663 if (target_has_execution)
668 { 664 {
669 /* Fetching registers from a live process requires that 665 /* Fetching registers from a live process requires that
670 inferior_ptid is a LWP value rather than a thread value. */ 666 inferior_ptid is a LWP value rather than a thread value. */
671 inferior_ptid = BUILD_LWP (lwp, main_ptid); 667 inferior_ptid = ptid_build (ptid_get_pid (main_ptid), lwp, 0);
672 beneath->to_fetch_registers (beneath, cache, -1); 668 beneath->to_fetch_registers (beneath, cache, -1);
673 } 669 }
674 else 670 else
675 { 671 {
676 /* Fetching registers from a core process requires that 672 /* Fetching registers from a core process requires that
677 the PID value of inferior_ptid have the funky value that 673 the PID value of inferior_ptid have the funky value that
678 the kernel drops rather than the real PID. Gross. */ 674 the kernel drops rather than the real PID. Gross. */
679 inferior_ptid = pid_to_ptid ((lwp << 16) | GET_PID (main_ptid)); 675 inferior_ptid = pid_to_ptid ((lwp << 16) | ptid_get_pid (main_ptid));
680 beneath->to_fetch_registers (ops, cache, -1); 676 beneath->to_fetch_registers (ops, cache, -1);
681 } 677 }
682 678
683 ret = 0; 679 ret = 0;
684 switch (regset) 680 switch (regset)
685 { 681 {
686 case 0: 682 case 0:
687 fill_gregset (cache, (gregset_t *)buf, -1); 683 fill_gregset (cache, (gregset_t *)buf, -1);
688 break; 684 break;
689 case 1: 685 case 1:
690#ifdef HAVE_FPREGS 686#ifdef HAVE_FPREGS
691 fill_fpregset (cache, (fpregset_t *)buf, -1); 687 fill_fpregset (cache, (fpregset_t *)buf, -1);
692#endif 688#endif
@@ -719,27 +715,27 @@ nbsd_thread_proc_setregs (void *arg, int @@ -719,27 +715,27 @@ nbsd_thread_proc_setregs (void *arg, int
719 supply_gregset(cache, (gregset_t *)buf); 715 supply_gregset(cache, (gregset_t *)buf);
720 break; 716 break;
721 case 1: 717 case 1:
722#ifdef HAVE_FPREGS 718#ifdef HAVE_FPREGS
723 supply_fpregset(cache, (fpregset_t *)buf); 719 supply_fpregset(cache, (fpregset_t *)buf);
724#endif 720#endif
725 break; 721 break;
726 default: /* XXX need to handle other reg sets: SSE, AltiVec, etc. */ 722 default: /* XXX need to handle other reg sets: SSE, AltiVec, etc. */
727 ret = TD_ERR_INVAL; 723 ret = TD_ERR_INVAL;
728 } 724 }
729 725
730 /* Storing registers requires that inferior_ptid is a LWP value 726 /* Storing registers requires that inferior_ptid is a LWP value
731 rather than a thread value. */ 727 rather than a thread value. */
732 inferior_ptid = BUILD_LWP (lwp, main_ptid); 728 inferior_ptid = ptid_build (ptid_get_pid (main_ptid), lwp, 0);
733 beneath->to_store_registers (beneath, cache, -1); 729 beneath->to_store_registers (beneath, cache, -1);
734 do_cleanups (old_chain); 730 do_cleanups (old_chain);
735 731
736 return ret; 732 return ret;
737} 733}
738 734
739static void 735static void
740init_nbsd_proc_callbacks (void) 736init_nbsd_proc_callbacks (void)
741{ 737{
742 nbsd_thread_callbacks.proc_read = nbsd_thread_proc_read; 738 nbsd_thread_callbacks.proc_read = nbsd_thread_proc_read;
743 nbsd_thread_callbacks.proc_write = nbsd_thread_proc_write; 739 nbsd_thread_callbacks.proc_write = nbsd_thread_proc_write;
744 nbsd_thread_callbacks.proc_lookup = nbsd_thread_proc_lookup; 740 nbsd_thread_callbacks.proc_lookup = nbsd_thread_proc_lookup;
745 nbsd_thread_callbacks.proc_regsize = nbsd_thread_proc_regsize; 741 nbsd_thread_callbacks.proc_regsize = nbsd_thread_proc_regsize;