public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* Compilation Unit name
@ 2017-03-16 22:04 SASHA NICOLAS DA ROCHA PINHEIRO
  2017-03-16 22:06 ` Josh Stone
  0 siblings, 1 reply; 6+ messages in thread
From: SASHA NICOLAS DA ROCHA PINHEIRO @ 2017-03-16 22:04 UTC (permalink / raw)
  To: elfutils-devel


Hello guys,
I work for Dyninst, and I am moving from libdwarf to libdw. I am trying  to get the compilation unit name calling dwarf_nextcu, dwarf_offdie and  dwarf_diename, but it won't work as it works with libdwarf. I got NULL  as return from dwarf_diename. When I print the error messages after each  of these three function calls, I get no errors for the first two and an  "invalid dwarf" for the third one. Can you help me with it?
Below I present the snippet where I am doing the calls, both with libdwarf and libdw.

Sasha Nicolas



//Using libdwarf
bool Object::fix_global_symbol_modules_static_dwarf()
{
    /* Initialize libdwarf. */
    ::Dwarf **dbg_ptr = dwarf->type_dbg();
    if (!dbg_ptr)
        return false;
    ::Dwarf *dbg = *dbg_ptr;
    std::set<Dwarf_Off> dies_seen;
    dwarf_parse_aranges(dbg, dies_seen);

    /* Iterate over the compilation-unit headers. */
    size_t cu_header_size;
    for(Dwarf_Off cu_off = 0, next_cu_off;
        dwarf_nextcu(dbg, cu_off, &next_cu_off, &cu_header_size,
            NULL, NULL, NULL) == 0;
        cu_off = next_cu_off)
    {
        cerr << "Error message:" << dwarf_errmsg(-1) << endl;
        Dwarf_Die cu_die, *cu_die_p;
        cu_die_p = dwarf_offdie(dbg, next_cu_off /*cu_die_off*/, &cu_die);
        cerr << "Error message:" << dwarf_errmsg(-1) << endl;

        if(cu_die_p == NULL) continue;
        if(dies_seen.find(next_cu_off/* cu_die_off*/) != dies_seen.end()) continue;

        std::string modname;
        auto diename = dwarf_diename(&cu_die);
        cerr << "Error message:" << dwarf_errmsg(-1) << endl;
        if(diename == NULL)
        {
            modname = associated_symtab->file(); // default module
        }
        else
        {
            modname = diename;
        }

...


//Using libdwarf

bool Object::fix_global_symbol_modules_static_dwarf()
{
    /* Initialize libdwarf. */
    Dwarf_Debug *dbg_ptr = dwarf->type_dbg();
    if (!dbg_ptr)
        return false;
    Dwarf_Debug dbg = *dbg_ptr;
    std::set<Dwarf_Off> dies_seen;
    Dwarf_Off cu_die_off;
    Dwarf_Die cu_die;
    dwarf_parse_aranges(dbg, dies_seen);
    /* Iterate over the compilation-unit headers. */
    while (dwarf_next_cu_header_c(dbg, Dwarf_Bool(true),
                                  NULL,NULL,NULL,NULL,NULL,NULL,NULL,
                                  &cu_die_off, NULL) == DW_DLV_OK )
    {
        int status = dwarf_siblingof_b(dbg, NULL, Dwarf_Bool(true), &cu_die, NULL);
        assert(status == DW_DLV_OK);
        if(dies_seen.find(cu_die_off) != dies_seen.end()) continue;
        std::string modname;
        if(!DwarfWalker::findDieName(dbg, cu_die, modname))
        {
            modname = associated_symtab->file(); // default module
        }

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-03-17 17:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-16 22:04 Compilation Unit name SASHA NICOLAS DA ROCHA PINHEIRO
2017-03-16 22:06 ` Josh Stone
     [not found]   ` <BN3PR0601MB13452A525FF7EB29DC862A90A6260@BN3PR0601MB1345.namprd06.prod.outlook.com>
2017-03-17  0:29     ` Josh Stone
2017-03-17 17:18       ` SASHA NICOLAS DA ROCHA PINHEIRO
2017-03-17 17:37         ` Josh Stone
2017-03-17 16:07   ` SASHA NICOLAS DA ROCHA PINHEIRO

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).