2006-09-20 23:16:16 +02:00
|
|
|
// Copyright (c) 2006, Google Inc.
|
|
|
|
|
// All rights reserved.
|
2006-08-25 23:14:45 +02:00
|
|
|
//
|
2006-09-20 23:16:16 +02:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
|
// met:
|
2006-08-25 23:14:45 +02:00
|
|
|
//
|
2006-09-20 23:16:16 +02:00
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
|
// copyright notice, this list of conditions and the following disclaimer
|
|
|
|
|
// in the documentation and/or other materials provided with the
|
|
|
|
|
// distribution.
|
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
|
// contributors may be used to endorse or promote products derived from
|
|
|
|
|
// this software without specific prior written permission.
|
2006-08-25 23:14:45 +02:00
|
|
|
//
|
2006-09-20 23:16:16 +02:00
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2006-08-25 23:14:45 +02:00
|
|
|
|
2006-11-09 18:04:56 +01:00
|
|
|
#include <cstdio>
|
2006-08-25 23:14:45 +02:00
|
|
|
#include <string>
|
2007-02-14 20:51:05 +01:00
|
|
|
#include "google_breakpad/processor/basic_source_line_resolver.h"
|
|
|
|
|
#include "google_breakpad/processor/code_module.h"
|
|
|
|
|
#include "google_breakpad/processor/stack_frame.h"
|
2006-10-23 21:24:58 +02:00
|
|
|
#include "processor/linked_ptr.h"
|
2007-05-25 20:04:17 +02:00
|
|
|
#include "processor/logging.h"
|
2006-10-23 22:25:42 +02:00
|
|
|
#include "processor/scoped_ptr.h"
|
2009-12-23 23:32:14 +01:00
|
|
|
#include "processor/windows_frame_info.h"
|
2006-08-25 23:14:45 +02:00
|
|
|
|
|
|
|
|
#define ASSERT_TRUE(cond) \
|
|
|
|
|
if (!(cond)) { \
|
|
|
|
|
fprintf(stderr, "FAILED: %s at %s:%d\n", #cond, __FILE__, __LINE__); \
|
|
|
|
|
return false; \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define ASSERT_FALSE(cond) ASSERT_TRUE(!(cond))
|
|
|
|
|
|
|
|
|
|
#define ASSERT_EQ(e1, e2) ASSERT_TRUE((e1) == (e2))
|
|
|
|
|
|
2006-11-09 18:04:56 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
using std::string;
|
2007-02-14 20:51:05 +01:00
|
|
|
using google_breakpad::BasicSourceLineResolver;
|
|
|
|
|
using google_breakpad::CodeModule;
|
|
|
|
|
using google_breakpad::linked_ptr;
|
|
|
|
|
using google_breakpad::scoped_ptr;
|
|
|
|
|
using google_breakpad::StackFrame;
|
2009-12-23 23:32:14 +01:00
|
|
|
using google_breakpad::WindowsFrameInfo;
|
2006-11-09 18:04:56 +01:00
|
|
|
|
2006-12-05 23:52:28 +01:00
|
|
|
class TestCodeModule : public CodeModule {
|
|
|
|
|
public:
|
|
|
|
|
TestCodeModule(string code_file) : code_file_(code_file) {}
|
|
|
|
|
virtual ~TestCodeModule() {}
|
|
|
|
|
|
|
|
|
|
virtual u_int64_t base_address() const { return 0; }
|
Breakpad processor: Fix function and public symbol lookup.
In r480, I botched the change to make the comparisons that decide
whether an address falls within a function's range safe from overflow.
The original code said:
address >= function_base && address < function_base + function_size
which is fine unless the function abuts the end of the address space,
in which case the addition overflows and you get a false negative.
My change subtracted function_size from both sides of the latter
comparison, which is meaning-preserving in true math, and gets you:
address >= function_base && address - function_size < function_base
This not only reads strangely, but also still overflows if
function_size is greater than address. That's rare, but I've added a
case to the unit tests that checks it.
My intent had been to replace the addition which could overflow with a
subtraction that was known not to overflow, namely:
address >= function_base && address - function_base < function_size
This is equivalent to the original in true math, and because of the
first comparison, we know the subtraction won't underflow in MemAddr
math.
The patch includes similar fixes to the public symbol lookup code, and
to FindWindowsFrameInfo, which was the only other function affected by
r480.
a=jimblandy, r=mmentovai
git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@503 4c0a9323-5329-0410-9bdc-e9ce6186880e
2010-01-28 06:17:23 +01:00
|
|
|
virtual u_int64_t size() const { return 0xb000; }
|
2006-12-05 23:52:28 +01:00
|
|
|
virtual string code_file() const { return code_file_; }
|
|
|
|
|
virtual string code_identifier() const { return ""; }
|
|
|
|
|
virtual string debug_file() const { return ""; }
|
|
|
|
|
virtual string debug_identifier() const { return ""; }
|
|
|
|
|
virtual string version() const { return ""; }
|
|
|
|
|
virtual const CodeModule* Copy() const {
|
|
|
|
|
return new TestCodeModule(code_file_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
string code_file_;
|
|
|
|
|
};
|
|
|
|
|
|
2006-09-07 19:26:17 +02:00
|
|
|
static bool VerifyEmpty(const StackFrame &frame) {
|
|
|
|
|
ASSERT_TRUE(frame.function_name.empty());
|
|
|
|
|
ASSERT_TRUE(frame.source_file_name.empty());
|
|
|
|
|
ASSERT_EQ(frame.source_line, 0);
|
2006-08-25 23:14:45 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-23 21:24:58 +02:00
|
|
|
static void ClearSourceLineInfo(StackFrame *frame) {
|
2006-09-07 19:26:17 +02:00
|
|
|
frame->function_name.clear();
|
2006-12-05 23:52:28 +01:00
|
|
|
frame->module = NULL;
|
2006-09-07 19:26:17 +02:00
|
|
|
frame->source_file_name.clear();
|
|
|
|
|
frame->source_line = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-25 23:14:45 +02:00
|
|
|
static bool RunTests() {
|
|
|
|
|
string testdata_dir = string(getenv("srcdir") ? getenv("srcdir") : ".") +
|
|
|
|
|
"/src/processor/testdata";
|
|
|
|
|
|
2006-12-12 00:22:54 +01:00
|
|
|
BasicSourceLineResolver resolver;
|
2006-08-25 23:14:45 +02:00
|
|
|
ASSERT_TRUE(resolver.LoadModule("module1", testdata_dir + "/module1.out"));
|
2006-10-16 20:19:09 +02:00
|
|
|
ASSERT_TRUE(resolver.HasModule("module1"));
|
2006-08-25 23:14:45 +02:00
|
|
|
ASSERT_TRUE(resolver.LoadModule("module2", testdata_dir + "/module2.out"));
|
2006-10-16 20:19:09 +02:00
|
|
|
ASSERT_TRUE(resolver.HasModule("module2"));
|
2006-08-25 23:14:45 +02:00
|
|
|
|
2006-12-05 23:52:28 +01:00
|
|
|
TestCodeModule module1("module1");
|
|
|
|
|
|
2006-09-07 19:26:17 +02:00
|
|
|
StackFrame frame;
|
2010-02-05 19:09:17 +01:00
|
|
|
scoped_ptr<WindowsFrameInfo> windows_frame_info;
|
2006-09-07 19:26:17 +02:00
|
|
|
frame.instruction = 0x1000;
|
2006-12-05 23:52:28 +01:00
|
|
|
frame.module = NULL;
|
2010-01-11 23:31:50 +01:00
|
|
|
resolver.FillSourceLineInfo(&frame);
|
2006-12-05 23:52:28 +01:00
|
|
|
ASSERT_FALSE(frame.module);
|
|
|
|
|
ASSERT_TRUE(frame.function_name.empty());
|
|
|
|
|
ASSERT_EQ(frame.function_base, 0);
|
|
|
|
|
ASSERT_TRUE(frame.source_file_name.empty());
|
|
|
|
|
ASSERT_EQ(frame.source_line, 0);
|
|
|
|
|
ASSERT_EQ(frame.source_line_base, 0);
|
|
|
|
|
|
|
|
|
|
frame.module = &module1;
|
2010-01-11 23:31:50 +01:00
|
|
|
resolver.FillSourceLineInfo(&frame);
|
2006-09-07 19:26:17 +02:00
|
|
|
ASSERT_EQ(frame.function_name, "Function1_1");
|
2006-12-05 23:52:28 +01:00
|
|
|
ASSERT_TRUE(frame.module);
|
|
|
|
|
ASSERT_EQ(frame.module->code_file(), "module1");
|
|
|
|
|
ASSERT_EQ(frame.function_base, 0x1000);
|
2006-09-07 19:26:17 +02:00
|
|
|
ASSERT_EQ(frame.source_file_name, "file1_1.cc");
|
|
|
|
|
ASSERT_EQ(frame.source_line, 44);
|
2006-12-05 23:52:28 +01:00
|
|
|
ASSERT_EQ(frame.source_line_base, 0x1000);
|
2010-02-05 19:09:17 +01:00
|
|
|
windows_frame_info.reset(resolver.FindWindowsFrameInfo(&frame));
|
|
|
|
|
ASSERT_TRUE(windows_frame_info.get());
|
|
|
|
|
ASSERT_FALSE(windows_frame_info->allocates_base_pointer);
|
|
|
|
|
ASSERT_EQ(windows_frame_info->program_string,
|
2006-09-28 23:09:37 +02:00
|
|
|
"$eip 4 + ^ = $esp $ebp 8 + = $ebp $ebp ^ =");
|
2006-09-07 19:26:17 +02:00
|
|
|
|
2006-10-23 21:24:58 +02:00
|
|
|
ClearSourceLineInfo(&frame);
|
2006-09-07 19:26:17 +02:00
|
|
|
frame.instruction = 0x800;
|
2006-12-05 23:52:28 +01:00
|
|
|
frame.module = &module1;
|
2010-01-11 23:31:50 +01:00
|
|
|
resolver.FillSourceLineInfo(&frame);
|
2006-09-07 19:26:17 +02:00
|
|
|
ASSERT_TRUE(VerifyEmpty(frame));
|
2010-02-05 19:09:17 +01:00
|
|
|
windows_frame_info.reset(resolver.FindWindowsFrameInfo(&frame));
|
|
|
|
|
ASSERT_FALSE(windows_frame_info.get());
|
2006-09-07 19:26:17 +02:00
|
|
|
|
|
|
|
|
frame.instruction = 0x1280;
|
2010-01-11 23:31:50 +01:00
|
|
|
resolver.FillSourceLineInfo(&frame);
|
2006-09-07 19:26:17 +02:00
|
|
|
ASSERT_EQ(frame.function_name, "Function1_3");
|
|
|
|
|
ASSERT_TRUE(frame.source_file_name.empty());
|
|
|
|
|
ASSERT_EQ(frame.source_line, 0);
|
2010-02-05 19:09:17 +01:00
|
|
|
windows_frame_info.reset(resolver.FindWindowsFrameInfo(&frame));
|
|
|
|
|
ASSERT_TRUE(windows_frame_info.get());
|
|
|
|
|
ASSERT_FALSE(windows_frame_info->allocates_base_pointer);
|
|
|
|
|
ASSERT_TRUE(windows_frame_info->program_string.empty());
|
2006-09-07 19:26:17 +02:00
|
|
|
|
|
|
|
|
frame.instruction = 0x1380;
|
2010-01-11 23:31:50 +01:00
|
|
|
resolver.FillSourceLineInfo(&frame);
|
2006-09-07 19:26:17 +02:00
|
|
|
ASSERT_EQ(frame.function_name, "Function1_4");
|
|
|
|
|
ASSERT_TRUE(frame.source_file_name.empty());
|
|
|
|
|
ASSERT_EQ(frame.source_line, 0);
|
2010-02-05 19:09:17 +01:00
|
|
|
windows_frame_info.reset(resolver.FindWindowsFrameInfo(&frame));
|
|
|
|
|
ASSERT_TRUE(windows_frame_info.get());
|
|
|
|
|
ASSERT_FALSE(windows_frame_info->allocates_base_pointer);
|
|
|
|
|
ASSERT_FALSE(windows_frame_info->program_string.empty());
|
2006-09-07 19:26:17 +02:00
|
|
|
|
2007-03-23 00:20:17 +01:00
|
|
|
frame.instruction = 0x2000;
|
2010-02-05 19:09:17 +01:00
|
|
|
windows_frame_info.reset(resolver.FindWindowsFrameInfo(&frame));
|
|
|
|
|
ASSERT_FALSE(windows_frame_info.get());
|
2007-03-23 00:20:17 +01:00
|
|
|
|
Breakpad processor: Fix function and public symbol lookup.
In r480, I botched the change to make the comparisons that decide
whether an address falls within a function's range safe from overflow.
The original code said:
address >= function_base && address < function_base + function_size
which is fine unless the function abuts the end of the address space,
in which case the addition overflows and you get a false negative.
My change subtracted function_size from both sides of the latter
comparison, which is meaning-preserving in true math, and gets you:
address >= function_base && address - function_size < function_base
This not only reads strangely, but also still overflows if
function_size is greater than address. That's rare, but I've added a
case to the unit tests that checks it.
My intent had been to replace the addition which could overflow with a
subtraction that was known not to overflow, namely:
address >= function_base && address - function_base < function_size
This is equivalent to the original in true math, and because of the
first comparison, we know the subtraction won't underflow in MemAddr
math.
The patch includes similar fixes to the public symbol lookup code, and
to FindWindowsFrameInfo, which was the only other function affected by
r480.
a=jimblandy, r=mmentovai
git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@503 4c0a9323-5329-0410-9bdc-e9ce6186880e
2010-01-28 06:17:23 +01:00
|
|
|
frame.instruction = 0x2900;
|
|
|
|
|
frame.module = &module1;
|
|
|
|
|
resolver.FillSourceLineInfo(&frame);
|
|
|
|
|
ASSERT_EQ(frame.function_name, string("PublicSymbol"));
|
|
|
|
|
|
|
|
|
|
frame.instruction = 0x4000;
|
|
|
|
|
frame.module = &module1;
|
|
|
|
|
resolver.FillSourceLineInfo(&frame);
|
|
|
|
|
ASSERT_EQ(frame.function_name, string("LargeFunction"));
|
|
|
|
|
|
2006-12-05 23:52:28 +01:00
|
|
|
TestCodeModule module2("module2");
|
|
|
|
|
|
|
|
|
|
frame.instruction = 0x2181;
|
|
|
|
|
frame.module = &module2;
|
2010-01-11 23:31:50 +01:00
|
|
|
resolver.FillSourceLineInfo(&frame);
|
2006-09-07 19:26:17 +02:00
|
|
|
ASSERT_EQ(frame.function_name, "Function2_2");
|
2006-12-05 23:52:28 +01:00
|
|
|
ASSERT_EQ(frame.function_base, 0x2170);
|
|
|
|
|
ASSERT_TRUE(frame.module);
|
|
|
|
|
ASSERT_EQ(frame.module->code_file(), "module2");
|
2006-09-07 19:26:17 +02:00
|
|
|
ASSERT_EQ(frame.source_file_name, "file2_2.cc");
|
|
|
|
|
ASSERT_EQ(frame.source_line, 21);
|
2006-12-05 23:52:28 +01:00
|
|
|
ASSERT_EQ(frame.source_line_base, 0x2180);
|
2010-02-05 19:09:17 +01:00
|
|
|
windows_frame_info.reset(resolver.FindWindowsFrameInfo(&frame));
|
|
|
|
|
ASSERT_TRUE(windows_frame_info.get());
|
|
|
|
|
ASSERT_EQ(windows_frame_info->prolog_size, 1);
|
2006-08-25 23:14:45 +02:00
|
|
|
|
2006-10-20 21:50:01 +02:00
|
|
|
frame.instruction = 0x216f;
|
2010-01-11 23:31:50 +01:00
|
|
|
resolver.FillSourceLineInfo(&frame);
|
2006-10-20 21:50:01 +02:00
|
|
|
ASSERT_EQ(frame.function_name, "Public2_1");
|
|
|
|
|
|
2006-10-23 21:24:58 +02:00
|
|
|
ClearSourceLineInfo(&frame);
|
2006-10-20 21:50:01 +02:00
|
|
|
frame.instruction = 0x219f;
|
2006-12-05 23:52:28 +01:00
|
|
|
frame.module = &module2;
|
2006-10-23 21:24:58 +02:00
|
|
|
resolver.FillSourceLineInfo(&frame);
|
2006-10-20 21:50:01 +02:00
|
|
|
ASSERT_TRUE(frame.function_name.empty());
|
|
|
|
|
|
|
|
|
|
frame.instruction = 0x21a0;
|
2006-12-05 23:52:28 +01:00
|
|
|
frame.module = &module2;
|
2010-01-11 23:31:50 +01:00
|
|
|
resolver.FillSourceLineInfo(&frame);
|
2006-10-20 21:50:01 +02:00
|
|
|
ASSERT_EQ(frame.function_name, "Public2_2");
|
|
|
|
|
|
2006-08-25 23:14:45 +02:00
|
|
|
ASSERT_FALSE(resolver.LoadModule("module3",
|
|
|
|
|
testdata_dir + "/module3_bad.out"));
|
2006-10-16 20:19:09 +02:00
|
|
|
ASSERT_FALSE(resolver.HasModule("module3"));
|
2006-08-25 23:14:45 +02:00
|
|
|
ASSERT_FALSE(resolver.LoadModule("module4",
|
2007-03-23 00:20:17 +01:00
|
|
|
testdata_dir + "/module4_bad.out"));
|
2006-10-16 20:19:09 +02:00
|
|
|
ASSERT_FALSE(resolver.HasModule("module4"));
|
2007-03-23 00:20:17 +01:00
|
|
|
ASSERT_FALSE(resolver.LoadModule("module5",
|
|
|
|
|
testdata_dir + "/invalid-filename"));
|
|
|
|
|
ASSERT_FALSE(resolver.HasModule("module5"));
|
2006-10-16 20:19:09 +02:00
|
|
|
ASSERT_FALSE(resolver.HasModule("invalid-module"));
|
2006-08-25 23:14:45 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-09 18:04:56 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
2006-08-25 23:14:45 +02:00
|
|
|
int main(int argc, char **argv) {
|
2007-05-25 20:04:17 +02:00
|
|
|
BPLOG_INIT(&argc, &argv);
|
|
|
|
|
|
2006-08-25 23:14:45 +02:00
|
|
|
if (!RunTests()) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|