[gdb/symtab] Add get/set functions for per_cu->lang/unit_type
[binutils-gdb.git] / gdb / ada-lang.c
index 54bcd86ee7f292856f433119f9ad15899d388017..93e0c67613f0a927416d5618abacce71013b65de 100644 (file)
@@ -6492,7 +6492,8 @@ ada_tag_value_at_base_address (struct value *obj)
       tem = value_cast (ptr_type, tem);
       offset_to_top = value_as_long (value_ind (tem));
     }
-  else if (offset_to_top > 0)
+
+  if (offset_to_top > 0)
     {
       /* OFFSET_TO_TOP used to be a positive value to be subtracted
         from the base address.  This was however incompatible with
@@ -11969,8 +11970,7 @@ ada_unhandled_exception_name_addr_from_raise (void)
    Return zero if the address could not be computed, or if not relevant.  */
 
 static CORE_ADDR
-ada_exception_name_addr_1 (enum ada_exception_catchpoint_kind ex,
-                          struct breakpoint *b)
+ada_exception_name_addr_1 (enum ada_exception_catchpoint_kind ex)
 {
   struct ada_inferior_data *data = get_ada_inferior_data (current_inferior ());
 
@@ -12068,14 +12068,13 @@ ada_exception_message (void)
    and zero is returned.  */
 
 static CORE_ADDR
-ada_exception_name_addr (enum ada_exception_catchpoint_kind ex,
-                        struct breakpoint *b)
+ada_exception_name_addr (enum ada_exception_catchpoint_kind ex)
 {
   CORE_ADDR result = 0;
 
   try
     {
-      result = ada_exception_name_addr_1 (ex, b);
+      result = ada_exception_name_addr_1 (ex);
     }
 
   catch (const gdb_exception_error &e)
@@ -12104,38 +12103,59 @@ static std::string ada_exception_catchpoint_cond_string
    exception, in order to be able to re-set the condition expression
    when symbols change.  */
 
-/* An instance of this type is used to represent an Ada catchpoint
-   breakpoint location.  */
+/* An instance of this type is used to represent an Ada catchpoint.  */
 
-class ada_catchpoint_location : public bp_location
-{
-public:
-  ada_catchpoint_location (breakpoint *owner)
-    : bp_location (owner, bp_loc_software_breakpoint)
-  {}
+struct ada_catchpoint : public code_breakpoint
+{
+  ada_catchpoint (struct gdbarch *gdbarch_,
+                 enum ada_exception_catchpoint_kind kind,
+                 struct symtab_and_line sal,
+                 const char *addr_string_,
+                 bool tempflag,
+                 bool enabled,
+                 bool from_tty)
+    : code_breakpoint (gdbarch_, bp_catchpoint),
+      m_kind (kind)
+  {
+    add_location (sal);
 
-  /* The condition that checks whether the exception that was raised
-     is the specific exception the user specified on catchpoint
-     creation.  */
-  expression_up excep_cond_expr;
-};
+    /* Unlike most code_breakpoint types, Ada catchpoints are
+       pspace-specific.  */
+    gdb_assert (sal.pspace != nullptr);
+    this->pspace = sal.pspace;
 
-/* An instance of this type is used to represent an Ada catchpoint.  */
+    if (from_tty)
+      {
+       struct gdbarch *loc_gdbarch = get_sal_arch (sal);
+       if (!loc_gdbarch)
+         loc_gdbarch = gdbarch;
+
+       describe_other_breakpoints (loc_gdbarch,
+                                   sal.pspace, sal.pc, sal.section, -1);
+       /* FIXME: brobecker/2006-12-28: Actually, re-implement a special
+          version for exception catchpoints, because two catchpoints
+          used for different exception names will use the same address.
+          In this case, a "breakpoint ... also set at..." warning is
+          unproductive.  Besides, the warning phrasing is also a bit
+          inappropriate, we should use the word catchpoint, and tell
+          the user what type of catchpoint it is.  The above is good
+          enough for now, though.  */
+      }
 
-struct ada_catchpoint : public base_breakpoint
-{
-  explicit ada_catchpoint (enum ada_exception_catchpoint_kind kind)
-    : m_kind (kind)
-  {
+    enable_state = enabled ? bp_enabled : bp_disabled;
+    disposition = tempflag ? disp_del : disp_donttouch;
+    locspec = string_to_location_spec (&addr_string_,
+                                      language_def (language_ada));
+    language = language_ada;
   }
 
   struct bp_location *allocate_location () override;
   void re_set () override;
   void check_status (struct bpstat *bs) override;
-  enum print_stop_action print_it (struct bpstat *bs) override;
-  bool print_one (struct bp_location **) override;
-  void print_mention () override;
-  void print_recreate (struct ui_file *fp) override;
+  enum print_stop_action print_it (const bpstat *bs) const override;
+  bool print_one (bp_location **) const override;
+  void print_mention () const override;
+  void print_recreate (struct ui_file *fp) const override;
 
   /* The name of the specific exception the user specified.  */
   std::string excep_string;
@@ -12144,6 +12164,22 @@ struct ada_catchpoint : public base_breakpoint
   enum ada_exception_catchpoint_kind m_kind;
 };
 
+/* An instance of this type is used to represent an Ada catchpoint
+   breakpoint location.  */
+
+class ada_catchpoint_location : public bp_location
+{
+public:
+  explicit ada_catchpoint_location (ada_catchpoint *owner)
+    : bp_location (owner, bp_loc_software_breakpoint)
+  {}
+
+  /* The condition that checks whether the exception that was raised
+     is the specific exception the user specified on catchpoint
+     creation.  */
+  expression_up excep_cond_expr;
+};
+
 /* Parse the exception condition string in the context of each of the
    catchpoint's locations, and store them for later evaluation.  */
 
@@ -12212,7 +12248,7 @@ ada_catchpoint::re_set ()
 {
   /* Call the base class's method.  This updates the catchpoint's
      locations.  */
-  this->breakpoint::re_set ();
+  this->code_breakpoint::re_set ();
 
   /* Reparse the exception conditional expressions.  One for each
      location.  */
@@ -12297,7 +12333,7 @@ ada_catchpoint::check_status (bpstat *bs)
    catchpoint kinds.  */
 
 enum print_stop_action
-ada_catchpoint::print_it (bpstat *bs)
+ada_catchpoint::print_it (const bpstat *bs) const
 {
   struct ui_out *uiout = current_uiout;
 
@@ -12328,7 +12364,7 @@ ada_catchpoint::print_it (bpstat *bs)
       case ada_catch_exception_unhandled:
       case ada_catch_handlers:
        {
-         const CORE_ADDR addr = ada_exception_name_addr (m_kind, this);
+         const CORE_ADDR addr = ada_exception_name_addr (m_kind);
          char exception_name[256];
 
          if (addr != 0)
@@ -12385,7 +12421,7 @@ ada_catchpoint::print_it (bpstat *bs)
    catchpoint kinds.  */
 
 bool
-ada_catchpoint::print_one (struct bp_location **last_loc)
+ada_catchpoint::print_one (bp_location **last_loc) const
 { 
   struct ui_out *uiout = current_uiout;
   struct value_print_options opts;
@@ -12442,7 +12478,7 @@ ada_catchpoint::print_one (struct bp_location **last_loc)
    for all exception catchpoint kinds.  */
 
 void
-ada_catchpoint::print_mention ()
+ada_catchpoint::print_mention () const
 {
   struct ui_out *uiout = current_uiout;
 
@@ -12494,7 +12530,7 @@ ada_catchpoint::print_mention ()
    exception catchpoint kinds.  */
 
 void
-ada_catchpoint::print_recreate (struct ui_file *fp)
+ada_catchpoint::print_recreate (struct ui_file *fp) const
 {
   switch (m_kind)
     {
@@ -12519,7 +12555,7 @@ ada_catchpoint::print_recreate (struct ui_file *fp)
       default:
        internal_error (__FILE__, __LINE__, _("unexpected catchpoint type"));
     }
-  print_recreate_thread (this, fp);
+  print_recreate_thread (fp);
 }
 
 /* See ada-lang.h.  */
@@ -12759,9 +12795,9 @@ create_ada_exception_catchpoint (struct gdbarch *gdbarch,
   std::string addr_string;
   struct symtab_and_line sal = ada_exception_sal (ex_kind, &addr_string);
 
-  std::unique_ptr<ada_catchpoint> c (new ada_catchpoint (ex_kind));
-  init_ada_exception_breakpoint (c.get (), gdbarch, sal, addr_string.c_str (),
-                                tempflag, disabled, from_tty);
+  std::unique_ptr<ada_catchpoint> c
+    (new ada_catchpoint (gdbarch, ex_kind, sal, addr_string.c_str (),
+                        tempflag, disabled, from_tty));
   c->excep_string = excep_string;
   create_excep_cond_exprs (c.get (), ex_kind);
   if (!cond_string.empty ())