Implement pahole-like 'ptype /o' option
[deliverable/binutils-gdb.git] / gdb / typeprint.c
index 9d9d6f5a49a8e7d5038dc0dba6223e8ced253b7c..15a62bef3cb090a28fc530f47901c3efc235fa74 100644 (file)
@@ -42,6 +42,7 @@ const struct type_print_options type_print_raw_options =
   1,                           /* raw */
   1,                           /* print_methods */
   1,                           /* print_typedefs */
+  0,                           /* print_offsets */
   0,                           /* print_nested_type_limit  */
   NULL,                                /* local_typedefs */
   NULL,                                /* global_table */
@@ -55,6 +56,7 @@ static struct type_print_options default_ptype_flags =
   0,                           /* raw */
   1,                           /* print_methods */
   1,                           /* print_typedefs */
+  0,                           /* print_offsets */
   0,                           /* print_nested_type_limit  */
   NULL,                                /* local_typedefs */
   NULL,                                /* global_table */
@@ -440,6 +442,20 @@ whatis_exp (const char *exp, int show)
                case 'T':
                  flags.print_typedefs = 1;
                  break;
+               case 'o':
+                 {
+                   /* Filter out languages which don't implement the
+                      feature.  */
+                   if (show > 0 &&
+                       (current_language->la_language == language_c
+                        || current_language->la_language == language_cplus))
+                     {
+                       flags.print_offsets = 1;
+                       flags.print_typedefs = 0;
+                       flags.print_methods = 0;
+                     }
+                   break;
+                 }
                default:
                  error (_("unrecognized flag '%c'"), *exp);
                }
@@ -499,6 +515,11 @@ whatis_exp (const char *exp, int show)
        real_type = value_rtti_type (val, &full, &top, &using_enc);
     }
 
+  if (flags.print_offsets
+      && (TYPE_CODE (type) == TYPE_CODE_STRUCT
+         || TYPE_CODE (type) == TYPE_CODE_UNION))
+    fprintf_filtered (gdb_stdout, "/* offset    |  size */  ");
+
   printf_filtered ("type = ");
 
   if (!flags.raw)
@@ -759,7 +780,8 @@ Available FLAGS are:\n\
   /m    do not print methods defined in a class\n\
   /M    print methods defined in a class\n\
   /t    do not print typedefs defined in a class\n\
-  /T    print typedefs defined in a class"));
+  /T    print typedefs defined in a class\n\
+  /o    print offsets and sizes of fields in a struct (like pahole)\n"));
   set_cmd_completer (c, expression_completer);
 
   c = add_com ("whatis", class_vars, whatis_command,
This page took 0.024104 seconds and 4 git commands to generate.