Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: gdb/cp-support.c

Issue 11969036: Merge GDB 7.5.1 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@master
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gdb/cp-support.h ('k') | gdb/cp-valprint.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Helper routines for C++ support in GDB. 1 /* Helper routines for C++ support in GDB.
2 Copyright (C) 2002-2005, 2007-2012 Free Software Foundation, Inc. 2 Copyright (C) 2002-2005, 2007-2012 Free Software Foundation, Inc.
3 3
4 Contributed by MontaVista Software. 4 Contributed by MontaVista Software.
5 5
6 This file is part of GDB. 6 This file is part of GDB.
7 7
8 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or 10 the Free Software Foundation; either version 3 of the License, or
(...skipping 16 matching lines...) Expand all
27 #include "dictionary.h" 27 #include "dictionary.h"
28 #include "objfiles.h" 28 #include "objfiles.h"
29 #include "frame.h" 29 #include "frame.h"
30 #include "symtab.h" 30 #include "symtab.h"
31 #include "block.h" 31 #include "block.h"
32 #include "complaints.h" 32 #include "complaints.h"
33 #include "gdbtypes.h" 33 #include "gdbtypes.h"
34 #include "exceptions.h" 34 #include "exceptions.h"
35 #include "expression.h" 35 #include "expression.h"
36 #include "value.h" 36 #include "value.h"
37 #include "cp-abi.h"
37 38
38 #include "safe-ctype.h" 39 #include "safe-ctype.h"
39 40
40 #include "psymtab.h" 41 #include "psymtab.h"
41 42
42 #define d_left(dc) (dc)->u.s_binary.left 43 #define d_left(dc) (dc)->u.s_binary.left
43 #define d_right(dc) (dc)->u.s_binary.right 44 #define d_right(dc) (dc)->u.s_binary.right
44 45
45 /* Functions related to demangled name parsing. */ 46 /* Functions related to demangled name parsing. */
46 47
(...skipping 18 matching lines...) Expand all
65 66
66 /* The list of "maint cplus" commands. */ 67 /* The list of "maint cplus" commands. */
67 68
68 struct cmd_list_element *maint_cplus_cmd_list = NULL; 69 struct cmd_list_element *maint_cplus_cmd_list = NULL;
69 70
70 /* The actual commands. */ 71 /* The actual commands. */
71 72
72 static void maint_cplus_command (char *arg, int from_tty); 73 static void maint_cplus_command (char *arg, int from_tty);
73 static void first_component_command (char *arg, int from_tty); 74 static void first_component_command (char *arg, int from_tty);
74 75
75 /* Operator validation.
76 NOTE: Multi-byte operators (usually the assignment variety
77 operator) must appear before the single byte version, i.e., "+="
78 before "+". */
79 static const char *operator_tokens[] =
80 {
81 "++", "+=", "+", "->*", "->", "--", "-=", "-", "*=", "*",
82 "/=", "/", "%=", "%", "!=", "==", "!", "&&", "<<=", "<<",
83 ">>=", ">>", "<=", "<", ">=", ">", "~", "&=", "&", "|=",
84 "||", "|", "^=", "^", "=", "()", "[]", ",", "new", "delete"
85 /* new[] and delete[] require special whitespace handling */
86 };
87
88 /* A list of typedefs which should not be substituted by replace_typedefs. */ 76 /* A list of typedefs which should not be substituted by replace_typedefs. */
89 static const char * const ignore_typedefs[] = 77 static const char * const ignore_typedefs[] =
90 { 78 {
91 "std::istream", "std::iostream", "std::ostream", "std::string" 79 "std::istream", "std::iostream", "std::ostream", "std::string"
92 }; 80 };
93 81
94 static void 82 static void
95 replace_typedefs (struct demangle_parse_info *info, 83 replace_typedefs (struct demangle_parse_info *info,
96 struct demangle_component *ret_comp); 84 struct demangle_component *ret_comp);
97 85
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 return NULL; 509 return NULL;
522 510
523 info = cp_demangled_name_to_comp (string, NULL); 511 info = cp_demangled_name_to_comp (string, NULL);
524 if (info == NULL) 512 if (info == NULL)
525 return NULL; 513 return NULL;
526 514
527 estimated_len = strlen (string) * 2; 515 estimated_len = strlen (string) * 2;
528 ret = cp_comp_to_string (info->tree, estimated_len); 516 ret = cp_comp_to_string (info->tree, estimated_len);
529 cp_demangled_name_parse_free (info); 517 cp_demangled_name_parse_free (info);
530 518
519 if (ret == NULL)
520 {
521 warning (_("internal error: string \"%s\" failed to be canonicalized"),
522 string);
523 return NULL;
524 }
525
531 if (strcmp (string, ret) == 0) 526 if (strcmp (string, ret) == 0)
532 { 527 {
533 xfree (ret); 528 xfree (ret);
534 return NULL; 529 return NULL;
535 } 530 }
536 531
537 return ret; 532 return ret;
538 } 533 }
539 534
540 /* Convert a mangled name to a demangle_component tree. *MEMORY is 535 /* Convert a mangled name to a demangle_component tree. *MEMORY is
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 return sym_return_val; 1133 return sym_return_val;
1139 } 1134 }
1140 1135
1141 /* Add all symbols with a name matching NAME in BLOCK to the overload 1136 /* Add all symbols with a name matching NAME in BLOCK to the overload
1142 list. */ 1137 list. */
1143 1138
1144 static void 1139 static void
1145 make_symbol_overload_list_block (const char *name, 1140 make_symbol_overload_list_block (const char *name,
1146 const struct block *block) 1141 const struct block *block)
1147 { 1142 {
1148 struct dict_iterator iter; 1143 struct block_iterator iter;
1149 struct symbol *sym; 1144 struct symbol *sym;
1150 1145
1151 const struct dictionary *dict = BLOCK_DICT (block); 1146 for (sym = block_iter_name_first (block, name, &iter);
1152
1153 for (sym = dict_iter_name_first (dict, name, &iter);
1154 sym != NULL; 1147 sym != NULL;
1155 sym = dict_iter_name_next (name, &iter)) 1148 sym = block_iter_name_next (name, &iter))
1156 overload_list_add_symbol (sym, name); 1149 overload_list_add_symbol (sym, name);
1157 } 1150 }
1158 1151
1159 /* Adds the function FUNC_NAME from NAMESPACE to the overload set. */ 1152 /* Adds the function FUNC_NAME from NAMESPACE to the overload set. */
1160 1153
1161 static void 1154 static void
1162 make_symbol_overload_list_namespace (const char *func_name, 1155 make_symbol_overload_list_namespace (const char *func_name,
1163 const char *namespace) 1156 const char *namespace)
1164 { 1157 {
1165 const char *name; 1158 const char *name;
(...skipping 25 matching lines...) Expand all
1191 } 1184 }
1192 1185
1193 /* Search the namespace of the given type and namespace of and public 1186 /* Search the namespace of the given type and namespace of and public
1194 base types. */ 1187 base types. */
1195 1188
1196 static void 1189 static void
1197 make_symbol_overload_list_adl_namespace (struct type *type, 1190 make_symbol_overload_list_adl_namespace (struct type *type,
1198 const char *func_name) 1191 const char *func_name)
1199 { 1192 {
1200 char *namespace; 1193 char *namespace;
1201 char *type_name; 1194 const char *type_name;
1202 int i, prefix_len; 1195 int i, prefix_len;
1203 1196
1204 while (TYPE_CODE (type) == TYPE_CODE_PTR 1197 while (TYPE_CODE (type) == TYPE_CODE_PTR
1205 || TYPE_CODE (type) == TYPE_CODE_REF 1198 || TYPE_CODE (type) == TYPE_CODE_REF
1206 || TYPE_CODE (type) == TYPE_CODE_ARRAY 1199 || TYPE_CODE (type) == TYPE_CODE_ARRAY
1207 || TYPE_CODE (type) == TYPE_CODE_TYPEDEF) 1200 || TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1208 { 1201 {
1209 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) 1202 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1210 type = check_typedef(type); 1203 type = check_typedef(type);
1211 else 1204 else
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 make_symbol_overload_list_namespace (func_name, namespace); 1313 make_symbol_overload_list_namespace (func_name, namespace);
1321 } 1314 }
1322 1315
1323 /* This does the bulk of the work of finding overloaded symbols. 1316 /* This does the bulk of the work of finding overloaded symbols.
1324 FUNC_NAME is the name of the overloaded function we're looking for 1317 FUNC_NAME is the name of the overloaded function we're looking for
1325 (possibly including namespace info). */ 1318 (possibly including namespace info). */
1326 1319
1327 static void 1320 static void
1328 make_symbol_overload_list_qualified (const char *func_name) 1321 make_symbol_overload_list_qualified (const char *func_name)
1329 { 1322 {
1330 struct symbol *sym;
1331 struct symtab *s; 1323 struct symtab *s;
1332 struct objfile *objfile; 1324 struct objfile *objfile;
1333 const struct block *b, *surrounding_static_block = 0; 1325 const struct block *b, *surrounding_static_block = 0;
1334 struct dict_iterator iter;
1335 const struct dictionary *dict;
1336 1326
1337 /* Look through the partial symtabs for all symbols which begin by 1327 /* Look through the partial symtabs for all symbols which begin by
1338 matching FUNC_NAME. Make sure we read that symbol table in. */ 1328 matching FUNC_NAME. Make sure we read that symbol table in. */
1339 1329
1340 ALL_OBJFILES (objfile) 1330 ALL_OBJFILES (objfile)
1341 { 1331 {
1342 if (objfile->sf) 1332 if (objfile->sf)
1343 objfile->sf->qf->expand_symtabs_for_function (objfile, func_name); 1333 objfile->sf->qf->expand_symtabs_for_function (objfile, func_name);
1344 } 1334 }
1345 1335
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 prefix = alloca (len + 1); 1434 prefix = alloca (len + 1);
1445 1435
1446 memcpy (prefix, arg, len); 1436 memcpy (prefix, arg, len);
1447 prefix[len] = '\0'; 1437 prefix[len] = '\0';
1448 1438
1449 printf_unfiltered ("%s\n", prefix); 1439 printf_unfiltered ("%s\n", prefix);
1450 } 1440 }
1451 1441
1452 extern initialize_file_ftype _initialize_cp_support; /* -Wmissing-prototypes */ 1442 extern initialize_file_ftype _initialize_cp_support; /* -Wmissing-prototypes */
1453 1443
1454 #define SKIP_SPACE(P) \
1455 do \
1456 { \
1457 while (*(P) == ' ' || *(P) == '\t') \
1458 ++(P); \
1459 } \
1460 while (0)
1461 1444
1462 /* Returns the length of the operator name or 0 if INPUT does not 1445 /* Implement "info vtbl". */
1463 point to a valid C++ operator. INPUT should start with 1446
1464 "operator". */ 1447 static void
1465 int 1448 info_vtbl_command (char *arg, int from_tty)
1466 cp_validate_operator (const char *input)
1467 { 1449 {
1468 int i; 1450 struct value *value;
1469 char *copy;
1470 const char *p;
1471 struct expression *expr;
1472 struct value *val;
1473 struct gdb_exception except;
1474 1451
1475 p = input; 1452 value = parse_and_eval (arg);
1476 1453 cplus_print_vtable (value);
1477 if (strncmp (p, "operator", 8) == 0)
1478 {
1479 int valid = 0;
1480
1481 p += 8;
1482 SKIP_SPACE (p);
1483 for (i = 0;
1484 » i < sizeof (operator_tokens) / sizeof (operator_tokens[0]);
1485 » ++i)
1486 » {
1487 » int length = strlen (operator_tokens[i]);
1488
1489 » /* By using strncmp here, we MUST have operator_tokens
1490 » ordered! See additional notes where operator_tokens is
1491 » defined above. */
1492 » if (strncmp (p, operator_tokens[i], length) == 0)
1493 » {
1494 » const char *op = p;
1495
1496 » valid = 1;
1497 » p += length;
1498
1499 » if (strncmp (op, "new", 3) == 0
1500 » » || strncmp (op, "delete", 6) == 0)
1501 » » {
1502
1503 » » /* Special case: new[] and delete[]. We must be
1504 » » careful to swallow whitespace before/in "[]". */
1505 » » SKIP_SPACE (p);
1506
1507 » » if (*p == '[')
1508 » » {
1509 » » ++p;
1510 » » SKIP_SPACE (p);
1511 » » if (*p == ']')
1512 » » » ++p;
1513 » » else
1514 » » » valid = 0;
1515 » » }
1516 » » }
1517
1518 » if (valid)
1519 » » return (p - input);
1520 » }
1521 » }
1522
1523 /* Check input for a conversion operator. */
1524
1525 /* Skip past base typename. */
1526 while (*p != '*' && *p != '&' && *p != 0 && *p != ' ')
1527 » ++p;
1528 SKIP_SPACE (p);
1529
1530 /* Add modifiers '*' / '&'. */
1531 while (*p == '*' || *p == '&')
1532 » {
1533 » ++p;
1534 » SKIP_SPACE (p);
1535 » }
1536
1537 /* Check for valid type. [Remember: input starts with
1538 » "operator".] */
1539 copy = savestring (input + 8, p - input - 8);
1540 expr = NULL;
1541 val = NULL;
1542 TRY_CATCH (except, RETURN_MASK_ALL)
1543 » {
1544 » expr = parse_expression (copy);
1545 » val = evaluate_type (expr);
1546 » }
1547
1548 xfree (copy);
1549 if (expr)
1550 » xfree (expr);
1551
1552 if (val != NULL && value_type (val) != NULL)
1553 » return (p - input);
1554 }
1555
1556 return 0;
1557 } 1454 }
1558 1455
1559 void 1456 void
1560 _initialize_cp_support (void) 1457 _initialize_cp_support (void)
1561 { 1458 {
1562 add_prefix_cmd ("cplus", class_maintenance, 1459 add_prefix_cmd ("cplus", class_maintenance,
1563 maint_cplus_command, 1460 maint_cplus_command,
1564 _("C++ maintenance commands."), 1461 _("C++ maintenance commands."),
1565 &maint_cplus_cmd_list, 1462 &maint_cplus_cmd_list,
1566 "maintenance cplus ", 1463 "maintenance cplus ",
1567 0, &maintenancelist); 1464 0, &maintenancelist);
1568 add_alias_cmd ("cp", "cplus", 1465 add_alias_cmd ("cp", "cplus",
1569 class_maintenance, 1, 1466 class_maintenance, 1,
1570 &maintenancelist); 1467 &maintenancelist);
1571 1468
1572 add_cmd ("first_component", 1469 add_cmd ("first_component",
1573 class_maintenance, 1470 class_maintenance,
1574 first_component_command, 1471 first_component_command,
1575 _("Print the first class/namespace component of NAME."), 1472 _("Print the first class/namespace component of NAME."),
1576 &maint_cplus_cmd_list); 1473 &maint_cplus_cmd_list);
1474
1475 add_info ("vtbl", info_vtbl_command,
1476 _("Show the virtual function table for a C++ object.\n\
1477 Usage: info vtbl EXPRESSION\n\
1478 Evaluate EXPRESSION and display the virtual function table for the\n\
1479 resulting object."));
1577 } 1480 }
OLDNEW
« no previous file with comments | « gdb/cp-support.h ('k') | gdb/cp-valprint.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698