Commit 0a24e67a authored by Mike Stanton's avatar Mike Stanton Committed by Commit Bot

[Torque] Add source positions for Torque files

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.

A detailed guide on usage to follow (also on v8.dev).

Bug: v8:8418
Change-Id: Ib4226877ce4cae451bb4d0c546927e89f4e66b58
Reviewed-on: https://chromium-review.googlesource.com/c/1475473Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Michael Stanton <mvstanton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59636}
parent a44565f6
......@@ -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)")
......
......@@ -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