Skip to content

Commit

Permalink
add debug assert and change attribute.h
Browse files Browse the repository at this point in the history
  • Loading branch information
tromey committed Apr 15, 2022
1 parent 1a7c41d commit b3ed9b1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
39 changes: 20 additions & 19 deletions gdb/dwarf2/attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,41 +54,43 @@ struct attribute
/* Return the block value. The attribute must have block form. */
dwarf_block *as_block () const
{
gdb_assert (form_is_block ());
gdb_debug_assert (form_is_block ());
return u.blk;
}

/* Return the signature. The attribute must have signature
form. */
ULONGEST as_signature () const
{
gdb_assert (form == DW_FORM_ref_sig8);
gdb_debug_assert (form == DW_FORM_ref_sig8);
return u.signature;
}

/* Return the signed value. The attribute must have the appropriate
form. */
LONGEST as_signed () const
{
gdb_assert (form_is_signed ());
/* This is a debug assert because it causes a large performance
drop when enabled. See PR symtab/27937. */
gdb_debug_assert (form_is_signed ());
return u.snd;
}

/* Return the unsigned value, but only for attributes requiring
reprocessing. */
ULONGEST as_unsigned_reprocess () const
{
gdb_assert (form_requires_reprocessing ());
gdb_assert (requires_reprocessing);
gdb_debug_assert (form_requires_reprocessing ());
gdb_debug_assert (requires_reprocessing);
return u.unsnd;
}

/* Return the unsigned value. Requires that the form be an unsigned
form, and that reprocessing not be needed. */
ULONGEST as_unsigned () const
{
gdb_assert (form_is_unsigned ());
gdb_assert (!requires_reprocessing);
gdb_debug_assert (form_is_unsigned ());
gdb_debug_assert (!requires_reprocessing);
return u.unsnd;
}

Expand All @@ -109,9 +111,8 @@ struct attribute
{
if (form_is_unsigned ())
return as_unsigned ();
if (form_is_signed ())
return (ULONGEST)as_signed ();
gdb_assert (false);
gdb_debug_assert (form_is_signed ());
return (ULONGEST) as_signed ();
}

/* Return non-zero if ATTR's value is a section offset --- classes
Expand Down Expand Up @@ -200,15 +201,15 @@ struct attribute
flag indicates whether the value has been canonicalized. */
bool canonical_string_p () const
{
gdb_assert (form_is_string ());
gdb_debug_assert (form_is_string ());
return string_is_canonical;
}

/* Initialize this attribute to hold a non-canonical string
value. */
void set_string_noncanonical (const char *str)
{
gdb_assert (form_is_string ());
gdb_debug_assert (form_is_string ());
u.str = str;
string_is_canonical = 0;
requires_reprocessing = 0;
Expand All @@ -217,36 +218,36 @@ struct attribute
/* Set the canonical string value for this attribute. */
void set_string_canonical (const char *str)
{
gdb_assert (form_is_string ());
gdb_debug_assert (form_is_string ());
u.str = str;
string_is_canonical = 1;
}

/* Set the block value for this attribute. */
void set_block (dwarf_block *blk)
{
gdb_assert (form_is_block ());
gdb_debug_assert (form_is_block ());
u.blk = blk;
}

/* Set the signature value for this attribute. */
void set_signature (ULONGEST signature)
{
gdb_assert (form == DW_FORM_ref_sig8);
gdb_debug_assert (form == DW_FORM_ref_sig8);
u.signature = signature;
}

/* Set this attribute to a signed integer. */
void set_signed (LONGEST snd)
{
gdb_assert (form == DW_FORM_sdata || form == DW_FORM_implicit_const);
gdb_debug_assert (form == DW_FORM_sdata || form == DW_FORM_implicit_const);
u.snd = snd;
}

/* Set this attribute to an unsigned integer. */
void set_unsigned (ULONGEST unsnd)
{
gdb_assert (form_is_unsigned ());
gdb_debug_assert (form_is_unsigned ());
u.unsnd = unsnd;
requires_reprocessing = 0;
}
Expand All @@ -255,15 +256,15 @@ struct attribute
used only for those forms that require reprocessing. */
void set_unsigned_reprocess (ULONGEST unsnd)
{
gdb_assert (form_requires_reprocessing ());
gdb_debug_assert (form_requires_reprocessing ());
u.unsnd = unsnd;
requires_reprocessing = 1;
}

/* Set this attribute to an address. */
void set_address (CORE_ADDR addr)
{
gdb_assert (form == DW_FORM_addr
gdb_debug_assert (form == DW_FORM_addr
|| ((form == DW_FORM_addrx
|| form == DW_FORM_GNU_addr_index)
&& requires_reprocessing));
Expand Down
6 changes: 6 additions & 0 deletions gdbsupport/gdb_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,10 @@
internal_error (__FILE__, __LINE__, _("%s: " message), __func__, \
##__VA_ARGS__)

#ifdef _GLIBCXX_DEBUG
#define gdb_debug_assert(expr) gdb_assert (expr)
#else
#define gdb_debug_assert(expr)
#endif

#endif /* COMMON_GDB_ASSERT_H */

0 comments on commit b3ed9b1

Please sign in to comment.