[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/1475473
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Commit-Queue: Michael Stanton <mvstanton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59636}
This commit is contained in:
Mike Stanton 2019-02-15 12:02:53 +01:00 committed by Commit Bot
parent a44565f60f
commit 0a24e67a7f
5 changed files with 41 additions and 2 deletions

View File

@ -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();
}

View File

@ -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)")

View File

@ -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: \

View File

@ -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);

View File

@ -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);