Skip to content

Debug info demangling workaround #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions gcc/jit/dummy-frontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ along with GCC; see the file COPYING3. If not see
#include "target.h"
#include "jit-recording.h"
#include "print-tree.h"
#include "langhooks.h"

#include <mpfr.h>
#include <unordered_map>
Expand Down Expand Up @@ -195,6 +196,8 @@ static const attribute_spec jit_gnu_attributes[] =
attr_returns_twice_exclusions },
{ "sentinel", 0, 1, false, true, true, false,
handle_sentinel_attribute, NULL },
{ "jit_dwarf_short_name", 1, 1, false, false, false, false,
NULL, NULL },
{ "target", 1, -1, true, false, false, false,
handle_target_attribute, attr_target_exclusions },
{ "type generic", 0, 0, false, true, true, false,
Expand Down Expand Up @@ -1373,6 +1376,21 @@ jit_langhook_getdecls (void)
return NULL;
}

const char *
jit_langhook_dwarf_name (tree decl, int verbosity)
{
tree attr = NULL;
const char* name = NULL;
if (false
|| !(decl
&& FUNCTION_DECL == TREE_CODE(decl)
&& (attr = lookup_attribute("jit_dwarf_short_name", DECL_ATTRIBUTES(decl)))
&& (name = TREE_STRING_POINTER (TREE_VALUE(TREE_VALUE (attr))))))
return lhd_dwarf_name (decl, verbosity);
else
return name;
}

static tree
jit_langhook_eh_personality (void)
{
Expand Down
2 changes: 2 additions & 0 deletions gcc/jit/jit-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ namespace recording {
class statement;
class extended_asm;
class case_;
class debug_namespace;
class top_level_asm;

/* End of recording types. */
Expand All @@ -171,6 +172,7 @@ namespace playback {
class source_line;
class location;
class case_;
class debug_namespace;

/* End of playback types. */
}
Expand Down
45 changes: 45 additions & 0 deletions gcc/jit/jit-playback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,8 @@ const char* fn_attribute_to_string (gcc_jit_fn_attribute attr)
return "weak";
case GCC_JIT_FN_ATTRIBUTE_NONNULL:
return "nonnull";
case GCC_JIT_FN_ATTRIBUTE_JIT_DWARF_SHORT_NAME:
return "jit_dwarf_short_name";
case GCC_JIT_FN_ATTRIBUTE_MAX:
return NULL;
}
Expand Down Expand Up @@ -696,6 +698,10 @@ new_function (location *loc,
}
}

bool short_name_found = false;
bool should_test_short_name = get_bool_option(GCC_JIT_BOOL_OPTION_DEBUGINFO)
&& get_bool_option(GCC_JIT_BOOL_OPTION_MANGLED_FUNCTION_NAME);

for (auto attr: string_attributes)
{
gcc_jit_fn_attribute& name = std::get<0>(attr);
Expand All @@ -705,10 +711,21 @@ new_function (location *loc,
const char* attribute = fn_attribute_to_string (name);
tree ident = attribute ? get_identifier (attribute) : NULL;

if (should_test_short_name && GCC_JIT_FN_ATTRIBUTE_JIT_DWARF_SHORT_NAME == name) {
short_name_found = true;
should_test_short_name = false;
}

if (ident)
fn_attributes = tree_cons (ident, attribute_value, fn_attributes);
}

if (short_name_found)
{
SET_DECL_ASSEMBLER_NAME(fndecl, get_identifier(name));
TREE_PUBLIC(fndecl) = 1;
}

for (auto attr: int_array_attributes)
{
gcc_jit_fn_attribute& name = std::get<0>(attr);
Expand Down Expand Up @@ -2236,6 +2253,13 @@ set_personality_function (function *personality_function)
DECL_FUNCTION_PERSONALITY (m_inner_fndecl) = personality_function->as_fndecl ();
}


void
playback::function::set_parent_debug_namespace(tree parent_dbg_ns)
{
DECL_CONTEXT(this->m_inner_fndecl) = parent_dbg_ns;
}

/* Build a statement list for the function as a whole out of the
lists of statements for the individual blocks, building labels
for each block. */
Expand Down Expand Up @@ -4144,6 +4168,27 @@ playback::location::location (recording::location *loc,
{
}

/* Construct a playback::field instance (wrapping a tree). */

playback::debug_namespace *
playback::context::
new_debug_namespace (recording::debug_namespace *dbg_ns)
{
gcc_assert(dbg_ns->get_name());

tree decl = build_decl (UNKNOWN_LOCATION, NAMESPACE_DECL,
get_identifier (dbg_ns->get_name()), void_type_node);

if (dbg_ns->get_parent())
DECL_CONTEXT(decl) =
dbg_ns
->get_parent()
->get_playback_obj()
->as_tree();

return new debug_namespace (decl);
}

/* The active gcc::jit::playback::context instance. This is a singleton,
guarded by jit_mutex. */

Expand Down
20 changes: 20 additions & 0 deletions gcc/jit/jit-playback.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ along with GCC; see the file COPYING3. If not see
#include <utility> // for std::pair
#include <vector>

#include "jit-common.h"
#include "timevar.h"
#include "varasm.h"

Expand Down Expand Up @@ -253,6 +254,9 @@ class context : public log_user
set_bool_option (enum gcc_jit_bool_option opt,
int value);

debug_namespace *
new_debug_namespace (recording::debug_namespace *dbg_ns);

const char *
get_str_option (enum gcc_jit_str_option opt) const
{
Expand Down Expand Up @@ -523,6 +527,19 @@ class type : public wrapper
tree m_inner;
};

class debug_namespace : public wrapper
{
public:
debug_namespace (tree inner)
: m_inner(inner)
{}

tree as_tree () const { return m_inner; }

private:
tree m_inner;
};

class compound_type : public type
{
public:
Expand Down Expand Up @@ -582,6 +599,9 @@ class function : public wrapper
void
build_stmt_list ();

void
set_parent_debug_namespace(tree parent_dbg_ns);

void
postprocess ();

Expand Down
94 changes: 83 additions & 11 deletions gcc/jit/jit-recording.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ along with GCC; see the file COPYING3. If not see
#include "jit-builtins.h"
#include "jit-recording.h"
#include "jit-playback.h"
#include "langhooks.h"
#include <sstream>

/* This comes from diagnostic.cc. */
Expand All @@ -39,6 +40,10 @@ static const char *const diagnostic_kind_text[] = {
"must-not-happen"
};

extern struct lang_hooks lang_hooks;
extern const char * jit_langhook_dwarf_name (tree decl, int verbosity);
extern const char * lhd_dwarf_name (tree decl, int verbosity);

namespace gcc {
namespace jit {

Expand Down Expand Up @@ -1443,6 +1448,15 @@ recording::context::new_case (recording::rvalue *min_value,
return result;
}

recording::debug_namespace *
recording::context::new_debug_namespace (const char *name,
debug_namespace *parent)
{
recording::debug_namespace *result = new debug_namespace (this, new_string (name), parent);
record (result);
return result;
}

/* Set the given string option for this context, or add an error if
it's not recognized.

Expand Down Expand Up @@ -1520,6 +1534,8 @@ recording::context::set_bool_option (enum gcc_jit_bool_option opt,
return;
}
m_bool_options[opt] = value ? true : false;
if (GCC_JIT_BOOL_OPTION_MANGLED_FUNCTION_NAME == opt)
lang_hooks.dwarf_name = m_bool_options[opt] ? jit_langhook_dwarf_name : lhd_dwarf_name;
log_bool_option (opt);
}

Expand Down Expand Up @@ -1877,6 +1893,7 @@ static const char * const
"GCC_JIT_BOOL_OPTION_DUMP_EVERYTHING",
"GCC_JIT_BOOL_OPTION_SELFCHECK_GC",
"GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES",
"GCC_JIT_BOOL_OPTION_MANGLED_FUNCTION_NAME"
};

static const char * const
Expand Down Expand Up @@ -2447,6 +2464,48 @@ recording::location::write_reproducer (reproducer &r)
m_line, m_column);
}

/* The implementation of class gcc::jit::recording::debug_namespace. */

/* Implementation of recording::memento::replay_into for debug_namespace.

Create a new playback::debug_namespace and store it into the
recording::debug_namespace's m_playback_obj field. */

void
recording::debug_namespace::replay_into (replayer *r)
{
m_playback_obj = r->new_debug_namespace (this);
}

/* Implementation of recording::memento::make_debug_string for debug_namespace,
turning them into the usual form:
FILENAME:LINE:COLUMN
like we do when emitting diagnostics. */

recording::string *
recording::debug_namespace::make_debug_string ()
{
return string::from_printf (m_ctxt,
"%s",
m_name->c_str ());
}

/* Implementation of recording::memento::write_reproducer for debug_namespace. */

void
recording::debug_namespace::write_reproducer (reproducer &r)
{
const char *id = r.make_identifier (this, "loc");
r.write (" gcc_jit_debug_namespace *%s =\n"
" gcc_jit_context_new_debug_namespace (%s, /* gcc_jit_context *ctxt */\n"
" %s, /* const char *name */\n"
" %s, /* debug_namespace *parent */\n",
id,
r.get_identifier (get_context ()),
m_name->c_str (),
m_parent->get_debug_string());
}

/* The implementation of class gcc::jit::recording::type. */

/* Given a type T, get the type T*.
Expand Down Expand Up @@ -4415,6 +4474,7 @@ recording::function::function (context *ctxt,

m_params.safe_push (param);
}
m_parent_dbg_namespace = NULL;
}

/* Implementation of pure virtual hook recording::memento::replay_into
Expand All @@ -4431,17 +4491,22 @@ recording::function::replay_into (replayer *r)
FOR_EACH_VEC_ELT (m_params, i, param)
params.safe_push (param->playback_param ());

set_playback_obj (r->new_function (playback_location (r, m_loc),
m_kind,
m_return_type->playback_type (),
m_name->c_str (),
&params,
m_is_variadic,
m_builtin_id,
m_attributes,
m_string_attributes,
m_int_array_attributes,
m_is_target_builtin));
playback::function* new_func = r->new_function (playback_location (r, m_loc),
m_kind,
m_return_type->playback_type (),
m_name->c_str (),
&params,
m_is_variadic,
m_builtin_id,
m_attributes,
m_string_attributes,
m_int_array_attributes,
m_is_target_builtin);
if (m_parent_dbg_namespace
&& m_parent_dbg_namespace->get_playback_obj())
new_func->set_parent_debug_namespace(m_parent_dbg_namespace->get_playback_obj()->as_tree());

set_playback_obj (new_func);
}

/* Implementation of recording::memento::make_debug_string for
Expand Down Expand Up @@ -4798,6 +4863,13 @@ recording::function::add_integer_array_attribute (
std::vector<int> (value, value + length)));
}

void
recording::function::set_parent_debug_namespace (
recording::debug_namespace* dbg_namespace)
{
this->m_parent_dbg_namespace = dbg_namespace;
}

/* Implementation of recording::memento::make_debug_string for
functions. */

Expand Down
Loading