summaryrefslogtreecommitdiff
path: root/gdb.diff
blob: 01c23581c00846b1eb728d56220accc2e1f37e92 (plain)
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
diff -N --exclude nm.h --exclude gdb-gdb.gdb --exclude jit-reader.h --exclude Makefile --exclude observer.h --exclude observer.inc --exclude stamp-h --exclude stamp-xml --exclude version.c --exclude xml-builtin.c --exclude config.status --exclude config.log --exclude config.h --exclude config.cache --exclude configure --exclude init.c -U3 gdb-7.5-clean/gdb/buildsym.c gdb-7.5/gdb/buildsym.c
--- gdb-7.5-clean/gdb/buildsym.c	2012-07-13 21:26:10.000000000 +0100
+++ gdb-7.5/gdb/buildsym.c	2012-09-27 17:28:44.000000000 +0100
@@ -446,6 +446,12 @@
 record_block_range (struct block *block,
                     CORE_ADDR start, CORE_ADDR end_inclusive)
 {
+  if (!block) {
+    fprintf(stderr,"warning: block was null for address 0x%p\n", (void*) start);
+    fflush(stderr);
+    return;
+  }
+
   /* If this is any different from the range recorded in the block's
      own BLOCK_START and BLOCK_END, then note that the address map has
      become interesting.  Note that even if this block doesn't have
diff -N --exclude nm.h --exclude gdb-gdb.gdb --exclude jit-reader.h --exclude Makefile --exclude observer.h --exclude observer.inc --exclude stamp-h --exclude stamp-xml --exclude version.c --exclude xml-builtin.c --exclude config.status --exclude config.log --exclude config.h --exclude config.cache --exclude configure --exclude init.c -U3 gdb-7.5-clean/gdb/defs.h gdb-7.5/gdb/defs.h
--- gdb-7.5-clean/gdb/defs.h	2012-07-02 11:57:33.000000000 +0100
+++ gdb-7.5/gdb/defs.h	2012-09-26 11:26:16.000000000 +0100
@@ -206,6 +206,7 @@
     language_pascal,		/* Pascal */
     language_ada,		/* Ada */
     language_opencl,		/* OpenCL */
+    language_ocaml,             /* OCaml */
     language_minimal,		/* All other languages, minimal support only */
     nr_languages
   };
diff -N --exclude nm.h --exclude gdb-gdb.gdb --exclude jit-reader.h --exclude Makefile --exclude observer.h --exclude observer.inc --exclude stamp-h --exclude stamp-xml --exclude version.c --exclude xml-builtin.c --exclude config.status --exclude config.log --exclude config.h --exclude config.cache --exclude configure --exclude init.c -U3 gdb-7.5-clean/gdb/demangle.c gdb-7.5/gdb/demangle.c
--- gdb-7.5-clean/gdb/demangle.c	2012-01-04 08:17:00.000000000 +0000
+++ gdb-7.5/gdb/demangle.c	2012-09-27 12:45:23.000000000 +0100
@@ -51,7 +51,7 @@
 	       struct cmd_list_element *c, const char *value)
 {
   fprintf_filtered (file,
-		    _("Demangling of encoded C++/ObjC names "
+		    _("Demangling of encoded C++/ObjC/OCaml names "
 		      "when displaying symbols is %s.\n"),
 		    value);
 }
@@ -64,7 +64,7 @@
 		   struct cmd_list_element *c, const char *value)
 {
   fprintf_filtered (file,
-		    _("Demangling of C++/ObjC names in "
+		    _("Demangling of C++/ObjC/OCaml names in "
 		      "disassembly listings is %s.\n"),
 		    value);
 }
@@ -218,15 +218,15 @@
       xstrdup (libiberty_demanglers[i].demangling_style_name);
 
   add_setshow_boolean_cmd ("demangle", class_support, &demangle, _("\
-Set demangling of encoded C++/ObjC names when displaying symbols."), _("\
-Show demangling of encoded C++/ObjC names when displaying symbols."), NULL,
+Set demangling of encoded C++/ObjC/OCaml names when displaying symbols."), _("\
+Show demangling of encoded C++/ObjC/OCaml names when displaying symbols."), NULL,
 			   NULL,
 			   show_demangle,
 			   &setprintlist, &showprintlist);
 
   add_setshow_boolean_cmd ("asm-demangle", class_support, &asm_demangle, _("\
-Set demangling of C++/ObjC names in disassembly listings."), _("\
-Show demangling of C++/ObjC names in disassembly listings."), NULL,
+Set demangling of C++/ObjC/OCaml names in disassembly listings."), _("\
+Show demangling of C++/ObjC/OCaml names in disassembly listings."), NULL,
 			   NULL,
 			   show_asm_demangle,
 			   &setprintlist, &showprintlist);
diff -N --exclude nm.h --exclude gdb-gdb.gdb --exclude jit-reader.h --exclude Makefile --exclude observer.h --exclude observer.inc --exclude stamp-h --exclude stamp-xml --exclude version.c --exclude xml-builtin.c --exclude config.status --exclude config.log --exclude config.h --exclude config.cache --exclude configure --exclude init.c -U3 gdb-7.5-clean/gdb/dwarf2read.c gdb-7.5/gdb/dwarf2read.c
--- gdb-7.5-clean/gdb/dwarf2read.c	2012-07-20 18:59:04.000000000 +0100
+++ gdb-7.5/gdb/dwarf2read.c	2012-09-27 12:23:24.000000000 +0100
@@ -65,6 +65,7 @@
 #include "gdb/gdb-index.h"
 #include <ctype.h>
 
+#include <stdio.h>
 #include <fcntl.h>
 #include "gdb_string.h"
 #include "gdb_assert.h"
@@ -7659,6 +7660,10 @@
   if (cu->producer && strstr (cu->producer, "GNU Go ") != NULL)
     set_cu_language (DW_LANG_Go, cu);
 
+  /* Likewise for OCaml.  */
+  if (cu->producer && strstr (cu->producer, "ocamlopt ") != NULL)
+    cu->language = language_ocaml;
+
   dwarf2_start_symtab (cu, name, comp_dir, lowpc);
 
   /* Decode line number information if present.  We do this before
diff -N --exclude nm.h --exclude gdb-gdb.gdb --exclude jit-reader.h --exclude Makefile --exclude observer.h --exclude observer.inc --exclude stamp-h --exclude stamp-xml --exclude version.c --exclude xml-builtin.c --exclude config.status --exclude config.log --exclude config.h --exclude config.cache --exclude configure --exclude init.c -U3 gdb-7.5-clean/gdb/eval.c gdb-7.5/gdb/eval.c
--- gdb-7.5-clean/gdb/eval.c	2012-07-09 15:20:51.000000000 +0100
+++ gdb-7.5/gdb/eval.c	2012-09-26 11:27:21.000000000 +0100
@@ -599,6 +599,7 @@
 	case language_asm:
 	case language_objc:
 	case language_opencl:
+	case language_ocaml:
 	  /* No promotion required.  */
 	  break;
 
@@ -667,6 +668,7 @@
 	case language_cplus:
 	case language_asm:
 	case language_objc:
+	case language_ocaml:
 	  if (result_len <= TYPE_LENGTH (builtin->builtin_int))
 	    {
 	      promoted_type = (unsigned_operation
diff -N --exclude nm.h --exclude gdb-gdb.gdb --exclude jit-reader.h --exclude Makefile --exclude observer.h --exclude observer.inc --exclude stamp-h --exclude stamp-xml --exclude version.c --exclude xml-builtin.c --exclude config.status --exclude config.log --exclude config.h --exclude config.cache --exclude configure --exclude init.c -U3 gdb-7.5-clean/gdb/Makefile.in gdb-7.5/gdb/Makefile.in
--- gdb-7.5-clean/gdb/Makefile.in	2012-07-02 16:29:33.000000000 +0100
+++ gdb-7.5/gdb/Makefile.in	2012-09-26 11:27:56.000000000 +0100
@@ -719,6 +719,7 @@
 	memrange.c mi/mi-common.c \
 	objc-exp.y objc-lang.c \
 	objfiles.c osabi.c observer.c osdata.c \
+	ocaml-lang.c \
 	opencl-lang.c \
 	p-exp.y p-lang.c p-typeprint.c p-valprint.c parse.c printcmd.c \
 	proc-service.list progspace.c \
@@ -895,7 +896,7 @@
 	varobj.o vec.o \
 	go-lang.o go-valprint.o go-typeprint.o \
 	jv-lang.o jv-valprint.o jv-typeprint.o \
-	m2-lang.o opencl-lang.o p-lang.o p-typeprint.o p-valprint.o \
+	m2-lang.o ocaml-lang.o opencl-lang.o p-lang.o p-typeprint.o p-valprint.o \
 	sentinel-frame.o \
 	complaints.o typeprint.o \
 	ada-typeprint.o c-typeprint.o f-typeprint.o m2-typeprint.o \
diff -N --exclude nm.h --exclude gdb-gdb.gdb --exclude jit-reader.h --exclude Makefile --exclude observer.h --exclude observer.inc --exclude stamp-h --exclude stamp-xml --exclude version.c --exclude xml-builtin.c --exclude config.status --exclude config.log --exclude config.h --exclude config.cache --exclude configure --exclude init.c -U3 gdb-7.5-clean/gdb/ocaml-lang.c gdb-7.5/gdb/ocaml-lang.c
--- gdb-7.5-clean/gdb/ocaml-lang.c	1970-01-01 01:00:00.000000000 +0100
+++ gdb-7.5/gdb/ocaml-lang.c	2012-09-27 16:41:51.000000000 +0100
@@ -0,0 +1,158 @@
+/* OCaml language support for GDB, the GNU debugger.
+   FIX COPYRIGHT NOTICE.
+
+   Contributed by Mark Shinwell <mshinwell@janestreet.com>
+
+   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 3 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, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "gdb_string.h"
+#include "gdbtypes.h"
+#include "symtab.h"
+#include "expression.h"
+#include "parser-defs.h"
+#include "symtab.h"
+#include "language.h"
+#include "c-lang.h"
+#include "gdb_assert.h"
+
+#include <ctype.h>
+
+extern const struct exp_descriptor exp_descriptor_c;
+
+char*
+ocaml_demangle(const char* mangled, int options);
+
+static int
+is_all_digits_after(char* chr)
+{
+  while (*++chr) {
+    if (!isdigit(*chr)) {
+      return 0;
+    }
+  }
+  return 1;
+}
+
+char*
+ocaml_demangle(const char* mangled, int options)
+{
+  char* demangled;
+  int index;
+  int output_index;
+  int mangled_length;
+  char* last_underscore;
+
+  demangled = XNEWVEC(char, strlen(mangled) + 1);
+
+  mangled_length = strlen(mangled);
+
+  output_index = 0;
+  if (strncmp(mangled, "caml", 4) != 0
+        || mangled_length < 5
+        || !isupper(mangled[4])
+        || strstr(mangled, "constant__symbol__")) {
+    strcpy(demangled, mangled);
+  }
+  else {
+    last_underscore = strrchr(mangled, '_');
+    if (last_underscore
+/*          && (*(last_underscore - 1) == '_')*/
+          && (/*!strcmp(last_underscore + 1, "entry")
+                ||*/ !strcmp(last_underscore + 1, "frametable")
+                || !strcmp(last_underscore + 1, "begin")
+                || !strcmp(last_underscore + 1, "end"))) {
+      strcpy(demangled, mangled);
+    }
+    else {
+      for (index = 4; index < mangled_length; index++) {
+        if (index > 4 &&
+              index < mangled_length - 1
+              && mangled[index] == '_' && mangled[index + 1] == '_') {
+          demangled[output_index] = '.';
+          index++;
+        }
+        else {
+          demangled[output_index] = mangled[index];
+        }
+
+        output_index++;
+      }
+
+      demangled[output_index] = '\0';
+    }
+
+    if (!strstr(mangled, "__anonfun_")) {
+      char* last_underscore = strrchr(demangled, '_');
+      if (last_underscore && is_all_digits_after(last_underscore)) {
+        *last_underscore = '\0';
+      }
+    }
+  }
+
+  return demangled;
+}
+
+const struct language_defn ocaml_language_defn =
+{
+  "ocaml",			/* Language name */
+  language_ocaml,
+  range_check_off,
+  type_check_off,
+  case_sensitive_on,
+  array_row_major,
+  macro_expansion_c,
+  &exp_descriptor_c,
+  c_parse,
+  c_error,
+  null_post_parser,
+  c_printchar,			/* Print a character constant */
+  c_printstr,			/* Function to print string constant */
+  c_emit_char,			/* Print a single char */
+  c_print_type,			/* Print a type using appropriate syntax */
+  c_print_typedef,		/* Print a typedef using appropriate syntax */
+  c_val_print,			/* Print a value using appropriate syntax */
+  c_value_print,		/* Print a top-level value */
+  default_read_var_value,	/* la_read_var_value */
+  NULL,				/* Language specific skip_trampoline */
+  NULL,				/* name_of_this */
+  basic_lookup_symbol_nonlocal,	/* lookup_symbol_nonlocal */
+  basic_lookup_transparent_type,/* lookup_transparent_type */
+  ocaml_demangle,               /* Language specific symbol demangler */
+  NULL,				/* Language specific
+				   class_name_from_physname */
+  c_op_print_tab,		/* expression operators for printing */
+  1,				/* c-style arrays */
+  0,				/* String lower bound */
+  default_word_break_characters,
+  default_make_symbol_completion_list,
+  c_language_arch_info,
+  default_print_array_index,
+  default_pass_by_reference,
+  c_get_string,
+  NULL,				/* la_get_symbol_name_cmp */
+  iterate_over_symbols,
+  LANG_MAGIC
+};
+
+/* Provide a prototype to silence -Wmissing-prototypes.  */
+extern initialize_file_ftype _initialize_ocaml_language;
+
+void
+_initialize_ocaml_language (void)
+{
+  add_language (&ocaml_language_defn);
+}
diff -N --exclude nm.h --exclude gdb-gdb.gdb --exclude jit-reader.h --exclude Makefile --exclude observer.h --exclude observer.inc --exclude stamp-h --exclude stamp-xml --exclude version.c --exclude xml-builtin.c --exclude config.status --exclude config.log --exclude config.h --exclude config.cache --exclude configure --exclude init.c -U3 gdb-7.5-clean/gdb/symtab.c gdb-7.5/gdb/symtab.c
--- gdb-7.5-clean/gdb/symtab.c	2012-07-16 04:07:01.000000000 +0100
+++ gdb-7.5/gdb/symtab.c	2012-09-27 15:36:50.000000000 +0100
@@ -63,6 +63,9 @@
 
 #include "psymtab.h"
 
+/* CR mshinwell: fixme */
+extern char* ocaml_demangle(const char*, int);
+
 /* Prototypes for local functions */
 
 static void rbreak_command (char *, int);
@@ -500,6 +503,7 @@
   gsymbol->language = language;
   if (gsymbol->language == language_d
       || gsymbol->language == language_go
+      || gsymbol->language == language_ocaml
       || gsymbol->language == language_java
       || gsymbol->language == language_objc
       || gsymbol->language == language_fortran)
@@ -635,6 +639,16 @@
 	  return demangled;
 	}
     }
+  if (gsymbol->language == language_ocaml
+      || gsymbol->language == language_auto)
+    {
+      demangled = ocaml_demangle (mangled, 0);
+      if (demangled != NULL)
+	{
+	  gsymbol->language = language_ocaml;
+	  return demangled;
+	}
+    }
 
   /* We could support `gsymbol->language == language_fortran' here to provide
      module namespaces also for inferiors with only minimal symbol table (ELF
@@ -825,6 +839,7 @@
     case language_cplus:
     case language_d:
     case language_go:
+    case language_ocaml:
     case language_java:
     case language_objc:
     case language_fortran:
@@ -856,6 +871,7 @@
     case language_cplus:
     case language_d:
     case language_go:
+    case language_ocaml:
     case language_java:
     case language_objc:
     case language_fortran:
@@ -1196,6 +1212,15 @@
 	  make_cleanup (xfree, demangled_name);
 	}
     }
+  else if (lang == language_ocaml)
+    {
+      demangled_name = ocaml_demangle (name, 0);
+      if (demangled_name)
+	{
+	  modified_name = demangled_name;
+	  make_cleanup (xfree, demangled_name);
+	}
+    }
 
   *result_name = modified_name;
   return cleanup;