-
Notifications
You must be signed in to change notification settings - Fork 298
/
gdb-6.3.patch
3001 lines (2978 loc) · 83.8 KB
/
gdb-6.3.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From f8ef37b6f0c824c1583278177b81312aef057361 Mon Sep 17 00:00:00 2001
From: Augustin Cavalier <waddlesplash@gmail.com>
Date: Sun, 2 Sep 2018 01:12:58 -0400
Subject: [PATCH] Merge changes from Haiku's main repo.
Includes some other fixes by me to get the build system fully working.
---
bfd/config.bfd | 8 +
config.sub | 3 +
gdb/Makefile.in | 2 +-
gdb/amd64-haiku-nat.c | 96 +++
gdb/amd64-haiku-tdep.c | 61 ++
gdb/config/i386/haiku.mh | 7 +
gdb/config/i386/haiku.mt | 5 +
gdb/config/i386/haiku64.mh | 7 +
gdb/config/i386/haiku64.mt | 5 +
gdb/config/i386/nm-haiku.h | 27 +
gdb/config/i386/tm-haiku.h | 27 +
gdb/config/nm-haiku.h | 25 +
gdb/config/tm-haiku.h | 25 +
gdb/configure.host | 3 +
gdb/configure.tgt | 2 +
gdb/defs.h | 2 +
gdb/haiku-nat.c | 1742 ++++++++++++++++++++++++++++++++++++++++++++
gdb/haiku-nat.h | 42 ++
gdb/haiku-tdep.c | 22 +
gdb/i386-haiku-nat.c | 87 +++
gdb/i386-haiku-tdep.c | 77 ++
gdb/osabi.c | 2 +
gdb/ser-tcp.c | 8 +-
gdb/solib-haiku.c | 334 +++++++++
gdb/solib-haiku.h | 34 +
libiberty/clock.c | 2 +-
readline/histfile.c | 4 +-
readline/input.c | 2 +-
readline/support/wcwidth.c | 1 +
29 files changed, 2654 insertions(+), 8 deletions(-)
create mode 100644 gdb/amd64-haiku-nat.c
create mode 100644 gdb/amd64-haiku-tdep.c
create mode 100644 gdb/config/i386/haiku.mh
create mode 100644 gdb/config/i386/haiku.mt
create mode 100644 gdb/config/i386/haiku64.mh
create mode 100644 gdb/config/i386/haiku64.mt
create mode 100644 gdb/config/i386/nm-haiku.h
create mode 100644 gdb/config/i386/tm-haiku.h
create mode 100644 gdb/config/nm-haiku.h
create mode 100644 gdb/config/tm-haiku.h
create mode 100644 gdb/haiku-nat.c
create mode 100644 gdb/haiku-nat.h
create mode 100644 gdb/haiku-tdep.c
create mode 100644 gdb/i386-haiku-nat.c
create mode 100644 gdb/i386-haiku-tdep.c
create mode 100644 gdb/solib-haiku.c
create mode 100644 gdb/solib-haiku.h
diff --git a/bfd/config.bfd b/bfd/config.bfd
index 549397b..79ceda9 100644
--- a/bfd/config.bfd
+++ b/bfd/config.bfd
@@ -532,6 +532,10 @@ case "${targ}" in
targ_defvec=bfd_elf64_x86_64_vec
targ_selvecs="bfd_elf32_i386_vec i386coff_vec bfd_efi_app_ia32_vec"
;;
+ x86_64-*-haiku*)
+ targ_defvec=bfd_elf64_x86_64_vec
+ targ_selvecs="bfd_elf32_i386_vec i386coff_vec bfd_efi_app_ia32_vec"
+ ;;
x86_64-*-netbsd* | x86_64-*-openbsd*)
targ_defvec=bfd_elf64_x86_64_vec
targ_selvecs="bfd_elf32_i386_vec i386netbsd_vec i386coff_vec bfd_efi_app_ia32_vec"
@@ -572,6 +576,10 @@ case "${targ}" in
targ_defvec=bfd_elf32_i386_vec
targ_selvecs="i386pe_vec i386pei_vec"
;;
+ i[3-7]86-*-haiku*)
+ targ_defvec=bfd_elf32_i386_vec
+ targ_selvecs="i386pe_vec i386pei_vec"
+ ;;
i[3-7]86-*-interix*)
targ_defvec=i386pei_vec
targ_selvecs="i386pe_vec"
diff --git a/config.sub b/config.sub
index edb6b66..36a7851 100755
--- a/config.sub
+++ b/config.sub
@@ -1297,6 +1297,9 @@ case $os in
-kaos*)
os=-kaos
;;
+ -haiku*)
+ os=-haiku
+ ;;
-none)
;;
*)
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 966f887..bfe9a41 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -374,7 +374,7 @@ INSTALLED_LIBS=-lbfd -lreadline -lopcodes -liberty \
-lintl -liberty
CLIBS = $(SIM) $(BFD) $(READLINE) $(OPCODES) $(INTL) $(LIBIBERTY) \
$(XM_CLIBS) $(TM_CLIBS) $(NAT_CLIBS) $(GDBTKLIBS) @LIBS@ \
- $(LIBICONV) \
+ $(LIBICONV) -ldebug \
$(LIBIBERTY) $(WIN32LIBS)
CDEPS = $(XM_CDEPS) $(TM_CDEPS) $(NAT_CDEPS) $(SIM) $(BFD) $(READLINE) \
$(OPCODES) $(INTL_DEPS) $(LIBIBERTY) $(CONFIG_DEPS)
diff --git a/gdb/amd64-haiku-nat.c b/gdb/amd64-haiku-nat.c
new file mode 100644
index 0000000..7a4ae51
--- /dev/null
+++ b/gdb/amd64-haiku-nat.c
@@ -0,0 +1,96 @@
+/* Native-dependent code for Haiku x86_64.
+
+ Copyright 2012 Alex Smith <alex@alex-smith.me.uk>.
+ Copyright 2005 Ingo Weinhold <bonefish@cs.tu-berlin.de>.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include "defs.h"
+#include "haiku-nat.h"
+#include "amd64-tdep.h"
+#include "i387-tdep.h"
+#include "inferior.h"
+#include "regcache.h"
+#include "target.h"
+
+/* Offset in `struct debug_cpu_state' where MEMBER is stored. */
+#define REG_OFFSET(member) offsetof (struct x86_64_debug_cpu_state, member)
+
+/* At kHaikuAMD64RegOffset[REGNUM] you'll find the offset in `struct
+ debug_cpu_state' where the GDB register REGNUM is stored. */
+static int kHaikuAMD64RegOffset[] = {
+ REG_OFFSET (rax),
+ REG_OFFSET (rbx),
+ REG_OFFSET (rcx),
+ REG_OFFSET (rdx),
+ REG_OFFSET (rsi),
+ REG_OFFSET (rdi),
+ REG_OFFSET (rbp),
+ REG_OFFSET (rsp),
+ REG_OFFSET (r8),
+ REG_OFFSET (r9),
+ REG_OFFSET (r10),
+ REG_OFFSET (r11),
+ REG_OFFSET (r12),
+ REG_OFFSET (r13),
+ REG_OFFSET (r14),
+ REG_OFFSET (r15),
+ REG_OFFSET (rip),
+ REG_OFFSET (rflags),
+ REG_OFFSET (cs),
+ REG_OFFSET (ss),
+ REG_OFFSET (ds),
+ REG_OFFSET (es),
+ REG_OFFSET (fs),
+ REG_OFFSET (gs)
+};
+
+
+void
+haiku_supply_registers(int reg, const debug_cpu_state *cpuState)
+{
+ if (reg == -1) {
+ int i;
+ for (i = 0; i < NUM_REGS; i++)
+ haiku_supply_registers(i, cpuState);
+ } else if (reg < AMD64_ST0_REGNUM) {
+ int offset = kHaikuAMD64RegOffset[reg];
+ regcache_raw_supply (current_regcache, reg, (char*)cpuState + offset);
+ } else {
+ amd64_supply_fxsave (current_regcache, -1,
+ &cpuState->extended_registers);
+ }
+}
+
+
+void
+haiku_collect_registers(int reg, debug_cpu_state *cpuState)
+{
+ if (reg == -1) {
+ int i;
+ for (i = 0; i < NUM_REGS; i++)
+ haiku_collect_registers(i, cpuState);
+ } else if (reg < AMD64_ST0_REGNUM) {
+ int offset = kHaikuAMD64RegOffset[reg];
+ regcache_raw_collect (current_regcache, reg, (char*)cpuState + offset);
+ } else {
+ amd64_collect_fxsave (current_regcache, -1,
+ &cpuState->extended_registers);
+ }
+}
+
diff --git a/gdb/amd64-haiku-tdep.c b/gdb/amd64-haiku-tdep.c
new file mode 100644
index 0000000..5923e58
--- /dev/null
+++ b/gdb/amd64-haiku-tdep.c
@@ -0,0 +1,61 @@
+/* Target-dependent code for Haiku x86_64.
+
+ Copyright 2012 Alex Smith <alex@alex-smith.me.uk>.
+ Copyright 2005 Ingo Weinhold <bonefish@cs.tu-berlin.de>.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include "defs.h"
+#include "gdbarch.h"
+#include "amd64-tdep.h"
+#include "osabi.h"
+
+
+static void
+amd64_haiku_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
+{
+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+ amd64_init_abi (info, gdbarch);
+
+ // the offset of the PC in the jmp_buf structure (cf. setjmp(), longjmp())
+ tdep->jb_pc_offset = 0;
+}
+
+
+static enum gdb_osabi
+amd64_haiku_osabi_sniffer (bfd * abfd)
+{
+ char *targetName = bfd_get_target (abfd);
+
+ if (strcmp (targetName, "elf64-x86-64") == 0)
+ return GDB_OSABI_HAIKU;
+
+ return GDB_OSABI_UNKNOWN;
+}
+
+
+void
+_initialize_amd64_haiku_tdep (void)
+{
+ gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_elf_flavour,
+ amd64_haiku_osabi_sniffer);
+
+ gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64, GDB_OSABI_HAIKU,
+ amd64_haiku_init_abi);
+}
diff --git a/gdb/config/i386/haiku.mh b/gdb/config/i386/haiku.mh
new file mode 100644
index 0000000..d4212db
--- /dev/null
+++ b/gdb/config/i386/haiku.mh
@@ -0,0 +1,7 @@
+# Host: Intel 586 running Haiku
+
+NAT_FILE= nm-haiku.h
+NATDEPFILES= haiku-nat.o i386-haiku-nat.o inf-child.o fork-child.o
+
+# No core file support yet.
+# corelow.o core-aout.o
diff --git a/gdb/config/i386/haiku.mt b/gdb/config/i386/haiku.mt
new file mode 100644
index 0000000..e60affb
--- /dev/null
+++ b/gdb/config/i386/haiku.mt
@@ -0,0 +1,5 @@
+# Target: Intel 586 running Haiku
+
+TDEPFILES= i386-tdep.o i386-haiku-tdep.o haiku-tdep.o i387-tdep.o \
+ solib.o solib-haiku.o symfile-mem.o
+DEPRECATED_TM_FILE= tm-haiku.h
diff --git a/gdb/config/i386/haiku64.mh b/gdb/config/i386/haiku64.mh
new file mode 100644
index 0000000..6381f4e
--- /dev/null
+++ b/gdb/config/i386/haiku64.mh
@@ -0,0 +1,7 @@
+# Host: Intel x86_64 running Haiku
+
+NAT_FILE= nm-haiku.h
+NATDEPFILES= haiku-nat.o amd64-haiku-nat.o inf-child.o fork-child.o
+
+# No core file support yet.
+# corelow.o core-aout.o
diff --git a/gdb/config/i386/haiku64.mt b/gdb/config/i386/haiku64.mt
new file mode 100644
index 0000000..cdacbb9
--- /dev/null
+++ b/gdb/config/i386/haiku64.mt
@@ -0,0 +1,5 @@
+# Target: Intel x86_64 running Haiku
+
+TDEPFILES= amd64-tdep.o amd64-haiku-tdep.o haiku-tdep.o i386-haiku-tdep.o \
+ i386-tdep.o i387-tdep.o solib.o solib-haiku.o symfile-mem.o
+DEPRECATED_TM_FILE= tm-haiku.h
diff --git a/gdb/config/i386/nm-haiku.h b/gdb/config/i386/nm-haiku.h
new file mode 100644
index 0000000..b392360
--- /dev/null
+++ b/gdb/config/i386/nm-haiku.h
@@ -0,0 +1,27 @@
+/* Native support for Haiku x86.
+
+ Copyright 2005 Ingo Weinhold <bonefish@cs.tu-berlin.de>.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef NM_HAIKU_H
+#define NM_HAIKU_H
+
+#include "config/nm-haiku.h"
+
+#endif /* nm-haiku.h */
diff --git a/gdb/config/i386/tm-haiku.h b/gdb/config/i386/tm-haiku.h
new file mode 100644
index 0000000..badfc7e
--- /dev/null
+++ b/gdb/config/i386/tm-haiku.h
@@ -0,0 +1,27 @@
+/* Definitions to target GDB to Haiku on 386.
+
+ Copyright 2005 Ingo Weinhold <bonefish@cs.tu-berlin.de>.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef TM_HAIKU_H
+#define TM_HAIKU_H
+
+#include "config/tm-haiku.h"
+
+#endif /* #ifndef TM_HAIKU_H */
diff --git a/gdb/config/nm-haiku.h b/gdb/config/nm-haiku.h
new file mode 100644
index 0000000..e85a1c2
--- /dev/null
+++ b/gdb/config/nm-haiku.h
@@ -0,0 +1,25 @@
+/* Native support Haiku.
+
+ Copyright 2005 Ingo Weinhold <bonefish@cs.tu-berlin.de>.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+// #define REALTIME_{LO,HI}?
+
+/* Support for shared libraries. */
+#include "solib.h"
diff --git a/gdb/config/tm-haiku.h b/gdb/config/tm-haiku.h
new file mode 100644
index 0000000..cdead7b
--- /dev/null
+++ b/gdb/config/tm-haiku.h
@@ -0,0 +1,25 @@
+/* Target support Haiku.
+
+ Copyright 2005 Ingo Weinhold <bonefish@cs.tu-berlin.de>.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+// #define REALTIME_{LO,HI}?
+
+/* Support for shared libraries. */
+#include "solib.h"
diff --git a/gdb/configure.host b/gdb/configure.host
index f730891..9ae107c 100644
--- a/gdb/configure.host
+++ b/gdb/configure.host
@@ -86,6 +86,7 @@ i[34567]86-*-unixware*) gdb_host=i386v4 ;;
i[34567]86-*-sysv*) gdb_host=i386v ;;
i[34567]86-*-isc*) gdb_host=i386v ;;
i[34567]86-*-cygwin*) gdb_host=cygwin ;;
+i[567]86-*-haiku*) gdb_host=haiku ;;
ia64-*-aix*) gdb_host=aix ;;
ia64-*-linux*) gdb_host=linux ;;
@@ -149,6 +150,8 @@ vax-*-ultrix*) gdb_host=vax ;;
x86_64-*-linux*) gdb_host=linux64 ;;
x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu)
gdb_host=fbsd64 ;;
+x86_64-*-haiku*)
+ gdb_host=haiku64 ;;
x86_64-*-netbsd* | x86_64-*-knetbsd*-gnu)
gdb_host=nbsd64 ;;
x86_64-*-openbsd*) gdb_host=obsd64 ;;
diff --git a/gdb/configure.tgt b/gdb/configure.tgt
index 0b1f627..4b75a9a 100644
--- a/gdb/configure.tgt
+++ b/gdb/configure.tgt
@@ -98,6 +98,7 @@ i[34567]86-*-netware*) gdb_target=i386
configdirs="${configdirs} nlm" ;;
i[34567]86-*-cygwin*) gdb_target=cygwin ;;
i[34567]86-*-vxworks*) gdb_target=vxworks ;;
+i[34567]86-*-haiku*) gdb_target=haiku ;;
i[34567]86-*-*) gdb_target=i386 ;;
ia64-*-aix*) gdb_target=aix ;;
@@ -217,6 +218,7 @@ v850*-*-*) gdb_target=v850
x86_64-*-linux*) gdb_target=linux64
build_gdbserver=yes
;;
+x86_64-*-haiku*) gdb_target=haiku64 ;;
x86_64-*-netbsd* | x86_64-*-knetbsd*-gnu)
gdb_target=nbsd64 ;;
x86_64-*-openbsd*) gdb_target=obsd64 ;;
diff --git a/gdb/defs.h b/gdb/defs.h
index fd96665..21dcda7 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -1052,6 +1052,8 @@ enum gdb_osabi
GDB_OSABI_CYGWIN,
+ GDB_OSABI_HAIKU,
+
GDB_OSABI_INVALID /* keep this last */
};
diff --git a/gdb/haiku-nat.c b/gdb/haiku-nat.c
new file mode 100644
index 0000000..01bc084
--- /dev/null
+++ b/gdb/haiku-nat.c
@@ -0,0 +1,1742 @@
+/* Haiku native-dependent code common to multiple platforms.
+
+ Copyright 2005 Ingo Weinhold <bonefish@cs.tu-berlin.de>.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <debugger.h>
+#include <image.h>
+#include <OS.h>
+
+#include <private/debug/debug_support.h>
+
+#include "defs.h" // include this first -- otherwise "command.h" will choke
+#include "command.h"
+#include "gdbcore.h"
+#include "gdbthread.h"
+#include "haiku-nat.h"
+#include "inferior.h"
+#include "observer.h"
+#include "regcache.h"
+#include "solib-haiku.h"
+#include "symfile.h"
+#include "target.h"
+
+//#define TRACE_HAIKU_NAT
+#ifdef TRACE_HAIKU_NAT
+ #define TRACE(x) printf x
+#else
+ #define TRACE(x) while (false) {}
+#endif
+
+static struct target_ops *sHaikuTarget = NULL;
+
+typedef struct debug_event {
+ struct debug_event *next;
+ debug_debugger_message message;
+ debug_debugger_message_data data;
+} debug_event;
+
+typedef struct debug_event_list {
+ debug_event *head;
+ debug_event *tail;
+} debug_event_list;
+
+typedef enum {
+ SIGNAL_ARRIVED, // the signal has actually arrived and is going to be
+ // handled (in any way)
+ SIGNAL_WILL_ARRIVE, // the signal has not yet been sent, but will be sent
+ // (e.g. an exception occurred and will cause the
+ // signal when not being ignored)
+ SIGNAL_FAKED, // the signal didn't arrive and won't arrive, we faked
+ // it (often in case of SIGTRAP)
+} pending_signal_status;
+
+typedef struct thread_debug_info {
+ struct thread_debug_info *next;
+ thread_id thread;
+ bool stopped;
+ debug_event *last_event; // last debug message from
+ // the thread; valid only,
+ // if stopped
+ int reprocess_event; // > 0, the event
+ // shall be processed a
+ // that many times, which
+ // will probably trigger
+ // another target event
+ int signal; // only valid, if stopped
+ pending_signal_status signal_status;
+} thread_debug_info;
+
+typedef struct extended_image_info {
+ haiku_image_info info;
+ struct extended_image_info *next;
+} extended_image_info;
+
+typedef struct team_debug_info {
+ team_id team;
+ port_id debugger_port;
+ thread_id nub_thread;
+ debug_context context;
+ thread_debug_info *threads;
+ extended_image_info *images;
+ debug_event_list events;
+} team_debug_info;
+
+static team_debug_info sTeamDebugInfo;
+
+
+typedef struct signal_map_entry {
+ enum target_signal target;
+ int haiku;
+} signal_map_entry;
+
+static const signal_map_entry sSignalMap[] = {
+ { TARGET_SIGNAL_0, 0 },
+ { TARGET_SIGNAL_HUP, SIGHUP },
+ { TARGET_SIGNAL_INT, SIGINT },
+ { TARGET_SIGNAL_QUIT, SIGQUIT },
+ { TARGET_SIGNAL_ILL, SIGILL },
+ { TARGET_SIGNAL_CHLD, SIGCHLD },
+ { TARGET_SIGNAL_ABRT, SIGABRT },
+ { TARGET_SIGNAL_PIPE, SIGPIPE },
+ { TARGET_SIGNAL_FPE, SIGFPE },
+ { TARGET_SIGNAL_KILL, SIGKILL },
+ { TARGET_SIGNAL_STOP, SIGSTOP },
+ { TARGET_SIGNAL_SEGV, SIGSEGV },
+ { TARGET_SIGNAL_CONT, SIGCONT },
+ { TARGET_SIGNAL_TSTP, SIGTSTP },
+ { TARGET_SIGNAL_ALRM, SIGALRM },
+ { TARGET_SIGNAL_TERM, SIGTERM },
+ { TARGET_SIGNAL_TTIN, SIGTTIN },
+ { TARGET_SIGNAL_TTOU, SIGTTOU },
+ { TARGET_SIGNAL_USR1, SIGUSR1 },
+ { TARGET_SIGNAL_USR2, SIGUSR2 },
+ { TARGET_SIGNAL_WINCH, SIGWINCH },
+ { TARGET_SIGNAL_TRAP, SIGTRAP },
+ { TARGET_SIGNAL_0, SIGKILLTHR }, // not debuggable anyway
+ { -1, -1 }
+};
+
+
+// #pragma mark -
+
+
+static char *haiku_pid_to_str (ptid_t ptid);
+
+
+static int
+target_to_haiku_signal(enum target_signal targetSignal)
+{
+ int i;
+
+ if (targetSignal < 0)
+ return -1;
+
+ for (i = 0; sSignalMap[i].target != -1 || sSignalMap[i].haiku != -1; i++) {
+ if (targetSignal == sSignalMap[i].target)
+ return sSignalMap[i].haiku;
+ }
+
+ return -1;
+}
+
+
+static enum target_signal
+haiku_to_target_signal(int haikuSignal)
+{
+ int i;
+
+ if (haikuSignal < 0)
+ return TARGET_SIGNAL_0;
+
+ for (i = 0; sSignalMap[i].target != -1 || sSignalMap[i].haiku != -1; i++) {
+ if (haikuSignal == sSignalMap[i].haiku)
+ return sSignalMap[i].target;
+ }
+
+ return TARGET_SIGNAL_UNKNOWN;
+}
+
+
+static thread_debug_info *
+haiku_find_thread(team_debug_info *teamDebugInfo, thread_id threadID)
+{
+ thread_debug_info *info;
+ for (info = teamDebugInfo->threads; info; info = info->next) {
+ if (info->thread == threadID)
+ return info;
+ }
+
+ return NULL;
+}
+
+
+static thread_debug_info *
+haiku_add_thread(team_debug_info *teamDebugInfo, thread_id threadID)
+{
+ struct thread_info *gdbThreadInfo;
+ thread_debug_info *threadDebugInfo;
+
+ if (threadID == teamDebugInfo->nub_thread) {
+ error("haiku_thread_added(): Trying to add debug nub thread (%ld)\n",
+ threadID);
+ }
+
+ // find the thread first
+ threadDebugInfo = haiku_find_thread(teamDebugInfo, threadID);
+ if (threadDebugInfo)
+ return threadDebugInfo;
+
+ // allocate a new thread debug info
+ threadDebugInfo = XMALLOC(thread_debug_info);
+ if (!threadDebugInfo)
+ error("haiku_thread_added(): Out of memory!\n");
+
+ // init and add it
+ threadDebugInfo->thread = threadID;
+ threadDebugInfo->next = teamDebugInfo->threads;
+ threadDebugInfo->stopped = false;
+ threadDebugInfo->last_event = NULL;
+ teamDebugInfo->threads = threadDebugInfo;
+
+ // add it to gdb's thread DB
+ gdbThreadInfo = add_thread(ptid_build(teamDebugInfo->team, 0, threadID));
+
+ // Note: In theory we could spare us the whole thread list management, since
+ // gdb's thread DB is doing exactly the same. We could put our data as
+ // thread_info::private. The only catch is that when the thread_info is
+ // freed, xfree() is invoked on the private data directly, but there's no
+ // callback invoked before that would allow us to do cleanup (e.g. free
+ // last_event).
+
+ TRACE(("haiku_add_thread(): team %ld thread %ld added: "
+ "gdb thread info: %p\n", teamDebugInfo->team, threadID, gdbThreadInfo));
+
+ return threadDebugInfo;
+}
+
+
+static void
+haiku_remove_thread(team_debug_info *teamDebugInfo, thread_id threadID)
+{
+ thread_debug_info **info;
+ for (info = &teamDebugInfo->threads; *info; info = &(*info)->next) {
+ if ((*info)->thread == threadID) {
+ thread_debug_info *foundInfo = *info;
+ *info = foundInfo->next;
+ if (foundInfo->last_event)
+ xfree(foundInfo->last_event);
+ xfree(foundInfo);
+
+ // remove it from gdb's thread DB
+ delete_thread(ptid_build(teamDebugInfo->team, 0, threadID));
+
+ return;
+ }
+ }
+}
+
+
+static void
+haiku_init_thread_list(team_debug_info *teamDebugInfo)
+{
+ thread_info threadInfo;
+ int32 cookie = 0;
+
+ // init gdb's thread DB
+ init_thread_list();
+
+ while (get_next_thread_info(teamDebugInfo->team, &cookie, &threadInfo)
+ == B_OK) {
+ if (threadInfo.thread != teamDebugInfo->nub_thread)
+ haiku_add_thread(teamDebugInfo, threadInfo.thread);
+ }
+}
+
+
+static void
+haiku_cleanup_thread_list(team_debug_info *teamDebugInfo)
+{
+ while (teamDebugInfo->threads) {
+ thread_debug_info *thread = teamDebugInfo->threads;
+ teamDebugInfo->threads = thread->next;
+ xfree(thread);
+ }
+
+ // clear gdb's thread DB
+ init_thread_list();
+}
+
+
+// #pragma mark -
+
+static extended_image_info **
+haiku_find_image_insert_location(team_debug_info *teamDebugInfo,
+ image_id imageID)
+{
+ extended_image_info **image;
+
+ for (image = &teamDebugInfo->images; *image; image = &(*image)->next) {
+ if ((*image)->info.id >= imageID)
+ return image;
+ }
+
+ return image;
+}
+
+
+static extended_image_info *
+haiku_find_image(team_debug_info *teamDebugInfo, image_id imageID)
+{
+ extended_image_info *image = *haiku_find_image_insert_location(
+ teamDebugInfo, imageID);
+
+ return (image && image->info.id == imageID ? image : NULL);
+}
+
+
+static extended_image_info *
+haiku_add_image(team_debug_info *teamDebugInfo, image_info *imageInfo)
+{
+ extended_image_info **imageP = haiku_find_image_insert_location(
+ teamDebugInfo, imageInfo->id);
+ extended_image_info *image = *imageP;
+
+ // already known?
+ if (image && image->info.id == imageInfo->id)
+ return image;
+
+ image = XMALLOC(extended_image_info);
+ if (!image)
+ error("haiku_add_image(): Out of memory!");
+
+ image->info.id = imageInfo->id;
+ strncpy(image->info.name, imageInfo->name, sizeof(image->info.name));
+ image->info.name[sizeof(image->info.name) - 1] = '\0';
+ // TODO: This should be the shared objects soname, not the path. We
+ // probably need to extend the debugger API.
+ strncpy(image->info.path, imageInfo->name, sizeof(image->info.path));
+ image->info.path[sizeof(image->info.path) - 1] = '\0';
+ image->info.text_address = (CORE_ADDR)imageInfo->text;
+ image->info.text_size = imageInfo->text_size;
+ image->info.data_address = (CORE_ADDR)imageInfo->data;
+ image->info.data_size = imageInfo->data_size;
+ image->info.is_app_image = (imageInfo->type == B_APP_IMAGE);
+
+ image->next = *imageP;
+ *imageP = image;
+
+ return image;
+}
+
+
+static void
+haiku_remove_image(team_debug_info *teamDebugInfo, image_id imageID)
+{
+ extended_image_info **imageP = haiku_find_image_insert_location(
+ teamDebugInfo, imageID);
+ extended_image_info *image = *imageP;
+
+ if (image && image->info.id == imageID) {
+ *imageP = image->next;
+ xfree(image);
+ }
+}
+
+
+static void
+haiku_init_image_list(team_debug_info *teamDebugInfo)
+{
+ int32 cookie = 0;
+ image_info info;
+ while (get_next_image_info(teamDebugInfo->team, &cookie, &info) == B_OK)
+ haiku_add_image(teamDebugInfo, &info);
+}
+
+
+static void
+haiku_cleanup_image_list(team_debug_info *teamDebugInfo)
+{
+ while (teamDebugInfo->images) {
+ extended_image_info *image = teamDebugInfo->images;
+ teamDebugInfo->images = image->next;
+ xfree(image);
+ }
+}
+
+
+/*
+ * Service function. Call with -1 the first time.
+ */
+struct haiku_image_info *
+haiku_get_next_image_info(int lastID)
+{
+ extended_image_info *image = *haiku_find_image_insert_location(
+ &sTeamDebugInfo, (lastID >= 0 ? lastID : 0));
+
+ if (image && image->info.id == lastID)
+ image = image->next;
+
+ return (image ? &image->info : NULL);
+}
+
+
+// #pragma mark -
+
+static debug_event *
+haiku_enqueue_debug_event(debug_event_list *list, int32 message,
+ debug_debugger_message_data *data, int32 size)
+{
+ debug_event *event = XMALLOC(debug_event);
+
+ if (!event)
+ error("haiku_enqueue_debug_event(): Out of memory!\n");
+
+ // init the event
+ event->next = NULL;
+ event->message = message;
+ memcpy(&event->data, data,
+ (size >= 0 ? size : sizeof(debug_debugger_message_data)));
+
+ // add it to the queue
+ if (list->tail) {
+ list->tail->next = event;
+ list->tail = event;
+ } else {
+ list->head = list->tail = event;
+ }
+
+ return event;
+}
+
+
+static debug_event *
+haiku_dequeue_next_debug_event(debug_event_list *list)
+{
+ debug_event *event = list->head;
+
+ if (event) {
+ // remove it from the queue
+ list->head = event->next;
+ if (list->tail == event)
+ list->tail = NULL;
+
+ event->next = NULL; // just because we're paranoid
+ }
+
+ return event;
+}
+
+
+static debug_event *
+haiku_remove_debug_event(debug_event_list *list, debug_event *eventToRemove)
+{
+ debug_event **event;
+
+ if (eventToRemove) {
+ for (event = &list->head; *event; event = &(*event)->next) {
+ if (*event == eventToRemove) {
+ *event = (*event)->next;
+ if (eventToRemove == list->tail)
+ list->tail = NULL;
+ return eventToRemove;
+ }
+ }
+ }
+
+ error("haiku_remove_debug_event(): event %p not found in list %p\n",
+ eventToRemove, list);
+
+ return NULL;
+}
+
+
+static void
+haiku_clear_debug_event_list(debug_event_list *list)
+{
+ debug_event *event;
+
+ while ((event = haiku_dequeue_next_debug_event(list)))
+ xfree(event);
+}
+
+
+static debug_event *
+haiku_find_next_debug_event(debug_event_list *list,
+ bool (*predicate)(void *closure, debug_event *event), void *closure)
+{
+ debug_event *event;