Skip to content

Commit

Permalink
Fix line number off-by-one errors
Browse files Browse the repository at this point in the history
  • Loading branch information
GJDuck committed Jun 26, 2024
1 parent 2137b6d commit 03375cf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
11 changes: 10 additions & 1 deletion src/e9tool/e9dwarf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,15 @@ extern const Line *e9tool::findLine(const Lines &Ls, intptr_t addr)
auto i = Ls.lower_bound(addr);
if (i == Ls.end())
return nullptr;
return &i->second;
if (i->second.lb == addr)
return &i->second;
auto j = Ls.begin();
if (i == j)
return nullptr;
i--;
if (i->second.lb <= addr && addr < i->second.ub)
return &i->second;
else
return nullptr;
}

30 changes: 14 additions & 16 deletions src/e9tool/e9metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1957,12 +1957,12 @@ static Type sendLoadArgumentMetadata(FILE *out, CallInfo &info,
case ARGUMENT_FILENAME: case ARGUMENT_ABSNAME:
case ARGUMENT_BASENAME: case ARGUMENT_DIRNAME:
{
auto i = elf->lines.lower_bound(I->address);
if (i != elf->lines.end())
const Line *line = findLine(elf->lines, I->address);
if (line != nullptr)
{
const auto &line = i->second;
if (arg.kind == ARGUMENT_DIRNAME &&
(line.dir == nullptr && strchr(line.file, '/') == nullptr))
(line->dir == nullptr &&
strchr(line->file, '/') == nullptr))
{
sendSExtFromI32ToR64(out, 0, regno);
t = TYPE_NULL_PTR;
Expand Down Expand Up @@ -1991,21 +1991,20 @@ static Type sendLoadArgumentMetadata(FILE *out, CallInfo &info,
}
case ARGUMENT_LINE:
{
auto i = elf->lines.lower_bound(I->address);
if (i == elf->lines.end())
const Line *line = findLine(elf->lines, I->address);
if (line == nullptr)
{
sendSExtFromI32ToR64(out, 0, regno);
t = TYPE_CONST_VOID_PTR;
break;
}
const Line &line = i->second;
switch (arg.field)
{
case FIELD_NONE:
sendLoadValueMetadata(out, line.line, regno);
sendLoadValueMetadata(out, line->line, regno);
break;
case FIELD_SIZE:
sendLoadValueMetadata(out, line.ub - line.lb, regno);
sendLoadValueMetadata(out, line->ub - line->lb, regno);
break;
default:
error("unknown field (%d)", arg.field);
Expand Down Expand Up @@ -2091,21 +2090,20 @@ static void sendArgumentDataMetadata(FILE *out, const char *name,
case ARGUMENT_FILENAME: case ARGUMENT_ABSNAME:
case ARGUMENT_BASENAME: case ARGUMENT_DIRNAME:
{
auto i = elf->lines.lower_bound(I->address);
if (i == elf->lines.end())
const Line *line = findLine(elf->lines, I->address);
if (line == nullptr)
return;
const auto &line = i->second;
std::string tmp;
const char *file = line.file, *kind = "file";
const char *file = line->file, *kind = "file";
switch (arg.kind)
{
case ARGUMENT_ABSNAME:
getAbsname(line.dir, line.file, tmp);
getAbsname(line->dir, line->file, tmp);
kind = "abs"; file = tmp.c_str(); break;
case ARGUMENT_BASENAME:
kind = "base"; file = getBasename(line.file); break;
kind = "base"; file = getBasename(line->file); break;
case ARGUMENT_DIRNAME:
getDirname(line.dir, line.file, tmp);
getDirname(line->dir, line->file, tmp);
kind = "dir"; file = tmp.c_str(); break;
default:
break;
Expand Down

0 comments on commit 03375cf

Please sign in to comment.