Commit b08c6947 authored by Mike Stanton's avatar Mike Stanton Committed by Commit Bot

Reland "[Torque] Add source positions for Torque files"

Reason for revert/reland: UBSan complained of unaligned reads.

To improve the Torque debugging experience, we can add source positions
for each line. This information is carried through the generated
CSA code (in <output directory>/gen/torque-generated/*.cc) and
embedded as SourcePositions in the Code object.

At snapshot time, these SourcePositions are stripped from the Code
object and turned into platform-appropriate line number debug
information.

At this time on Linux, you'll need to build with "is_clang=false"
in order to use GCC, because crucial steps are missing in Clang's
ability to convey the information into the binary successfully.

This CL also introduces a flag to control the existing source
information in CSA code. --enable-source-at-csa-bind is now set
to false by default because it's a bit confusing to "hop" between
source lines in .TQ files and in .CC files. I expect to continue
making adjustments there, as I want to provide helpful
debugging aids at the CSA level as well as the Torque level.
The current configuration prioritizes Torque.

TBR=tebbi@chromium.org

Bug: v8:8418
Change-Id: Idb80467d3679ec2361386fe9b67597b93d7f72cf
Reviewed-on: https://chromium-review.googlesource.com/c/1475763Reviewed-by: 's avatarMichael Stanton <mvstanton@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Michael Stanton <mvstanton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59657}
parent b6cf4f51
......@@ -1762,7 +1762,9 @@ void CodeAssemblerLabel::Bind(AssemblerDebugInfo debug_info) {
<< "\n# previous: " << *label_->block();
FATAL("%s", str.str().c_str());
}
state_->raw_assembler_->SetSourcePosition(debug_info.file, debug_info.line);
if (FLAG_enable_source_at_csa_bind) {
state_->raw_assembler_->SetSourcePosition(debug_info.file, debug_info.line);
}
state_->raw_assembler_->Bind(label_, debug_info);
UpdateVariablesAfterBind();
}
......
......@@ -850,6 +850,10 @@ DEFINE_STRING(mcpu, "auto", "enable optimization for specific cpu")
DEFINE_BOOL(partial_constant_pool, true,
"enable use of partial constant pools (X64 only)")
// Controlling source positions for Torque/CSA code.
DEFINE_BOOL(enable_source_at_csa_bind, false,
"Include source information in the binary at CSA bind locations.")
// Deprecated ARM flags (replaced by arm_arch).
DEFINE_MAYBE_BOOL(enable_armv7, "deprecated (use --arm_arch instead)")
DEFINE_MAYBE_BOOL(enable_vfp3, "deprecated (use --arm_arch instead)")
......
......@@ -322,15 +322,16 @@ class EmbeddedFileWriter : public EmbeddedFileWriterInterface {
static int WriteByteChunk(PlatformDependentEmbeddedFileWriter* w,
int current_line_length, const uint8_t* data) {
const uint64_t* quad_ptr1 = reinterpret_cast<const uint64_t*>(data);
const uint64_t* quad_ptr2 = reinterpret_cast<const uint64_t*>(data + 8);
const size_t size = kInt64Size;
uint64_t part1, part2;
// Use memcpy for the reads since {data} is not guaranteed to be aligned.
#ifdef V8_TARGET_BIG_ENDIAN
uint64_t part1 = *quad_ptr1;
uint64_t part2 = *quad_ptr2;
memcpy(&part1, data, size);
memcpy(&part2, data + size, size);
#else
uint64_t part1 = *quad_ptr2;
uint64_t part2 = *quad_ptr1;
memcpy(&part1, data + size, size);
memcpy(&part2, data, size);
#endif // V8_TARGET_BIG_ENDIAN
if (part1 != 0) {
......
......@@ -54,8 +54,20 @@ Stack<std::string> CSAGenerator::EmitBlock(const Block* block) {
return stack;
}
void CSAGenerator::EmitSourcePosition(SourcePosition pos, bool always_emit) {
const std::string& file = SourceFileMap::GetSource(pos.source);
if (always_emit || !previous_position_.CompareIgnoreColumn(pos)) {
// Lines in Torque SourcePositions are zero-based, while the
// CodeStubAssembler and downwind systems are one-based.
out_ << " ca_.SetSourcePosition(\"" << file << "\", " << (pos.line + 1)
<< ");\n";
previous_position_ = pos;
}
}
void CSAGenerator::EmitInstruction(const Instruction& instruction,
Stack<std::string>* stack) {
EmitSourcePosition(instruction->pos);
switch (instruction.kind()) {
#define ENUM_ITEM(T) \
case InstructionKind::k##T: \
......
......@@ -18,7 +18,10 @@ class CSAGenerator {
public:
CSAGenerator(const ControlFlowGraph& cfg, std::ostream& out,
base::Optional<Builtin::Kind> linkage = base::nullopt)
: cfg_(cfg), out_(out), linkage_(linkage) {}
: cfg_(cfg),
out_(out),
linkage_(linkage),
previous_position_(SourcePosition::Invalid()) {}
base::Optional<Stack<std::string>> EmitGraph(Stack<std::string> parameters);
static constexpr const char* ARGUMENTS_VARIABLE_STRING = "arguments";
......@@ -31,6 +34,9 @@ class CSAGenerator {
std::ostream& out_;
size_t fresh_id_ = 0;
base::Optional<Builtin::Kind> linkage_;
SourcePosition previous_position_;
void EmitSourcePosition(SourcePosition pos, bool always_emit = false);
std::string PreCallableExceptionPreparation(
base::Optional<Block*> catch_block);
......
......@@ -14,6 +14,10 @@ namespace internal {
namespace torque {
class SourceId {
public:
static SourceId Invalid() { return SourceId(-1); }
int operator==(const SourceId& s) const { return id_ == s.id_; }
private:
explicit SourceId(int id) : id_(id) {}
int id_;
......@@ -24,6 +28,17 @@ struct SourcePosition {
SourceId source;
int line;
int column;
static SourcePosition Invalid() {
SourcePosition pos{SourceId::Invalid(), -1, -1};
return pos;
}
int operator==(const SourcePosition& pos) const {
return line == pos.line && column == pos.column && source == pos.source;
}
int operator!=(const SourcePosition& pos) const { return !(*this == pos); }
bool CompareIgnoreColumn(const SourcePosition& pos) const {
return line == pos.line && source == pos.source;
}
};
DECLARE_CONTEXTUAL_VARIABLE(CurrentSourceFile, SourceId);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment