Skip to content

Commit 567dff6

Browse files
---
yaml --- r: 69096 b: refs/heads/auto c: a1c5c79 h: refs/heads/master v: v3
1 parent bdb2573 commit 567dff6

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: e9baeab695ffb0483ce6bef872f5d85c636dd04a
17+
refs/heads/auto: a1c5c798c7b8d7b556144ed3ba286936fb8ba639
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

branches/auto/src/librustc/middle/trans/debuginfo.rs

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@ where possible. This will hopefully ease the adaption of this module to future L
2727
2828
The public API of the module is a set of functions that will insert the correct metadata into the
2929
LLVM IR when called with the right parameters. The module is thus driven from an outside client with
30-
functions like `debuginfo::create_local_var_metadata(bcx: block, local: @ast::local)`.
30+
functions like `debuginfo::local_var_metadata(bcx: block, local: &ast::local)`.
3131
32-
Internally the module will try to reuse already created metadata by utilizing a cache. All private
33-
state used by the module is stored within a DebugContext struct, which in turn is contained in the
34-
CrateContext.
32+
Internally the module will try to reuse already created metadata by utilizing a cache. The way to
33+
get a shared metadata node when needed is thus to just call the corresponding function in this
34+
module:
35+
36+
let file_metadata = file_metadata(crate_context, path);
37+
38+
The function will take care of probing the cache for an existing node for that exact file path.
39+
40+
All private state used by the module is stored within a DebugContext struct, which in turn is
41+
contained in the CrateContext.
3542
3643
3744
This file consists of three conceptual sections:
@@ -149,7 +156,7 @@ pub fn create_local_var_metadata(bcx: block, local: @ast::local) -> DIVariable {
149156

150157
let context = match bcx.parent {
151158
None => create_function_metadata(bcx.fcx),
152-
Some(_) => block_metadata(bcx)
159+
Some(_) => lexical_block_metadata(bcx)
153160
};
154161

155162
let var_metadata = do as_c_str(name) |name| {
@@ -178,7 +185,7 @@ pub fn create_local_var_metadata(bcx: block, local: @ast::local) -> DIVariable {
178185
}
179186
};
180187

181-
set_debug_location(cx, block_metadata(bcx), loc.line, loc.col.to_uint());
188+
set_debug_location(cx, lexical_block_metadata(bcx), loc.line, loc.col.to_uint());
182189
unsafe {
183190
let instr = llvm::LLVMDIBuilderInsertDeclareAtEnd(DIB(cx), llptr, var_metadata, bcx.llbb);
184191
llvm::LLVMSetInstDebugLocation(trans::build::B(bcx), instr);
@@ -236,7 +243,7 @@ pub fn create_argument_metadata(bcx: block, arg: &ast::arg, span: span) -> Optio
236243
};
237244

238245
let llptr = fcx.llargs.get_copy(&arg.id);
239-
set_debug_location(cx, block_metadata(bcx), loc.line, loc.col.to_uint());
246+
set_debug_location(cx, lexical_block_metadata(bcx), loc.line, loc.col.to_uint());
240247
unsafe {
241248
let instr = llvm::LLVMDIBuilderInsertDeclareAtEnd(
242249
DIB(cx), llptr, var_metadata, bcx.llbb);
@@ -259,7 +266,7 @@ pub fn update_source_pos(bcx: block, span: span) {
259266
}
260267
debug!("update_source_pos: %s", bcx.sess().codemap.span_to_str(span));
261268
let loc = span_start(bcx.ccx(), span);
262-
set_debug_location(bcx.ccx(), block_metadata(bcx), loc.line, loc.col.to_uint())
269+
set_debug_location(bcx.ccx(), lexical_block_metadata(bcx), loc.line, loc.col.to_uint())
263270
}
264271

265272
/// Creates debug information for the given function.
@@ -418,44 +425,50 @@ fn file_metadata(cx: &mut CrateContext, full_path: &str) -> DIFile {
418425
return file_metadata;
419426
}
420427

421-
fn block_metadata(bcx: block) -> DILexicalBlock {
422-
let mut bcx = bcx;
428+
/// Get or create the lexical block metadata node for the given LLVM basic block.
429+
fn lexical_block_metadata(bcx: block) -> DILexicalBlock {
423430
let cx = bcx.ccx();
431+
let mut bcx = bcx;
424432

433+
// Search up the tree of basic blocks until we find one that knows the containing lexical block.
425434
while bcx.node_info.is_none() {
426435
match bcx.parent {
427-
Some(b) => bcx = b,
428-
None => fail!()
436+
Some(b) => bcx = b,
437+
None => cx.sess.bug("debuginfo: Could not find lexical block for LLVM basic block.")
429438
}
430439
}
440+
431441
let span = bcx.node_info.get().span;
432442
let id = bcx.node_info.get().id;
433443

444+
// Check whether we already have a cache entry for this node id
434445
match dbg_cx(cx).created_blocks.find(&id) {
435446
Some(block) => return *block,
436447
None => ()
437448
}
438449

439-
debug!("block_metadata: %s", bcx.sess().codemap.span_to_str(span));
450+
debug!("lexical_block_metadata: %s", bcx.sess().codemap.span_to_str(span));
440451

441452
let parent = match bcx.parent {
442453
None => create_function_metadata(bcx.fcx),
443-
Some(b) => block_metadata(b)
454+
Some(b) => lexical_block_metadata(b)
444455
};
445-
let cx = bcx.ccx();
456+
446457
let loc = span_start(cx, span);
447458
let file_metadata = file_metadata(cx, loc.file.name);
448459

449-
let block_metadata = unsafe {
460+
let lexical_block_metadata = unsafe {
450461
llvm::LLVMDIBuilderCreateLexicalBlock(
451462
DIB(cx),
452-
parent, file_metadata,
453-
loc.line as c_uint, loc.col.to_uint() as c_uint)
463+
parent,
464+
file_metadata,
465+
loc.line as c_uint,
466+
loc.col.to_uint() as c_uint)
454467
};
455468

456-
dbg_cx(cx).created_blocks.insert(id, block_metadata);
469+
dbg_cx(cx).created_blocks.insert(id, lexical_block_metadata);
457470

458-
return block_metadata;
471+
return lexical_block_metadata;
459472
}
460473

461474
fn basic_type_metadata(cx: &mut CrateContext, t: ty::t) -> DIType {

0 commit comments

Comments
 (0)