mirror of
				https://github.com/go-delve/delve.git
				synced 2025-10-31 02:36:18 +08:00 
			
		
		
		
	proc: keep track of nesting depth while reading compile units
Fully read compile units that contain nested entries we don't understand (such as DW_TAG_namespace) by keeping track of the depth we're at.
This commit is contained in:
		 aarzilli
					aarzilli
				
			
				
					committed by
					
						 Alessandro Arzilli
						Alessandro Arzilli
					
				
			
			
				
	
			
			
			 Alessandro Arzilli
						Alessandro Arzilli
					
				
			
						parent
						
							8571fddbc1
						
					
				
				
					commit
					136f4de4b8
				
			| @ -1618,6 +1618,8 @@ func (bi *BinaryInfo) loadDebugInfoMaps(image *Image, debugLineBytes []byte, wg | |||||||
| func (bi *BinaryInfo) loadDebugInfoMapsCompileUnit(ctxt *loadDebugInfoMapsContext, image *Image, reader *reader.Reader, cu *compileUnit) { | func (bi *BinaryInfo) loadDebugInfoMapsCompileUnit(ctxt *loadDebugInfoMapsContext, image *Image, reader *reader.Reader, cu *compileUnit) { | ||||||
| 	hasAttrGoPkgName := goversion.ProducerAfterOrEqual(cu.producer, 1, 13) | 	hasAttrGoPkgName := goversion.ProducerAfterOrEqual(cu.producer, 1, 13) | ||||||
|  |  | ||||||
|  | 	depth := 0 | ||||||
|  |  | ||||||
| 	for entry, err := reader.Next(); entry != nil; entry, err = reader.Next() { | 	for entry, err := reader.Next(); entry != nil; entry, err = reader.Next() { | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			image.setLoadError("error reading debug_info: %v", err) | 			image.setLoadError("error reading debug_info: %v", err) | ||||||
| @ -1625,7 +1627,11 @@ func (bi *BinaryInfo) loadDebugInfoMapsCompileUnit(ctxt *loadDebugInfoMapsContex | |||||||
| 		} | 		} | ||||||
| 		switch entry.Tag { | 		switch entry.Tag { | ||||||
| 		case 0: | 		case 0: | ||||||
|  | 			if depth == 0 { | ||||||
| 				return | 				return | ||||||
|  | 			} else { | ||||||
|  | 				depth-- | ||||||
|  | 			} | ||||||
| 		case dwarf.TagImportedUnit: | 		case dwarf.TagImportedUnit: | ||||||
| 			bi.loadDebugInfoMapsImportedUnit(entry, ctxt, image, cu) | 			bi.loadDebugInfoMapsImportedUnit(entry, ctxt, image, cu) | ||||||
| 			reader.SkipChildren() | 			reader.SkipChildren() | ||||||
| @ -1695,6 +1701,11 @@ func (bi *BinaryInfo) loadDebugInfoMapsCompileUnit(ctxt *loadDebugInfoMapsContex | |||||||
| 					bi.addConcreteSubprogram(entry, ctxt, reader, cu) | 					bi.addConcreteSubprogram(entry, ctxt, reader, cu) | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | 		default: | ||||||
|  | 			if entry.Children { | ||||||
|  | 				depth++ | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										6
									
								
								pkg/proc/dwarf_export_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								pkg/proc/dwarf_export_test.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | |||||||
|  | package proc | ||||||
|  |  | ||||||
|  | // PackageVars returns bi.packageVars (for tests) | ||||||
|  | func (bi *BinaryInfo) PackageVars() []packageVar { | ||||||
|  | 	return bi.packageVars | ||||||
|  | } | ||||||
| @ -337,3 +337,19 @@ func TestUnsupportedType(t *testing.T) { | |||||||
| 		t.Errorf("unexpected error reading unsupported type: %#v", err) | 		t.Errorf("unexpected error reading unsupported type: %#v", err) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func TestNestedCompileUnts(t *testing.T) { | ||||||
|  | 	// Tests that a compile unit with a nested entry that we don't care about | ||||||
|  | 	// (such as a DW_TAG_namespace) is read fully. | ||||||
|  | 	dwb := dwarfbuilder.New() | ||||||
|  | 	dwb.AddCompileUnit("main", 0x0) | ||||||
|  | 	dwb.TagOpen(dwarf.TagNamespace, "namespace") | ||||||
|  | 	dwb.AddVariable("var1", 0x0, uint64(0x0)) | ||||||
|  | 	dwb.TagClose() | ||||||
|  | 	dwb.AddVariable("var2", 0x0, uint64(0x0)) | ||||||
|  | 	dwb.TagClose() | ||||||
|  | 	bi, _ := fakeBinaryInfo(t, dwb) | ||||||
|  | 	if n := len(bi.PackageVars()); n != 2 { | ||||||
|  | 		t.Errorf("expected 2 variables, got %d", n) | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user