mirror of
				https://github.com/go-delve/delve.git
				synced 2025-10-31 10:47:27 +08:00 
			
		
		
		
	proc: simplify logic of (*stackIterator).newStackframe (#1513)
The lookup at it.pc-1 is only ever done if fn is not nil and pc != fn.entry. Also when it happens only the File and Line fields are allowed to change.
This commit is contained in:
		 Alessandro Arzilli
					Alessandro Arzilli
				
			
				
					committed by
					
						 Derek Parker
						Derek Parker
					
				
			
			
				
	
			
			
			 Derek Parker
						Derek Parker
					
				
			
						parent
						
							ac3b1c7a78
						
					
				
				
					commit
					09c92c75b9
				
			| @ -375,36 +375,21 @@ func (it *stackIterator) newStackframe(ret, retaddr uint64) Stackframe { | |||||||
| 		it.regs.FrameBase = it.frameBase(fn) | 		it.regs.FrameBase = it.frameBase(fn) | ||||||
| 	} | 	} | ||||||
| 	r := Stackframe{Current: Location{PC: it.pc, File: f, Line: l, Fn: fn}, Regs: it.regs, Ret: ret, addrret: retaddr, stackHi: it.stackhi, SystemStack: it.systemstack, lastpc: it.pc} | 	r := Stackframe{Current: Location{PC: it.pc, File: f, Line: l, Fn: fn}, Regs: it.regs, Ret: ret, addrret: retaddr, stackHi: it.stackhi, SystemStack: it.systemstack, lastpc: it.pc} | ||||||
| 	if !it.top { | 	r.Call = r.Current | ||||||
| 		fnname := "" | 	if !it.top && r.Current.Fn != nil && it.pc != r.Current.Fn.Entry { | ||||||
| 		if r.Current.Fn != nil { | 		// if the return address is the entry point of the function that | ||||||
| 			fnname = r.Current.Fn.Name | 		// contains it then this is some kind of fake return frame (for example | ||||||
| 		} | 		// runtime.sigreturn) that didn't actually call the current frame, | ||||||
| 		switch fnname { | 		// attempting to get the location of the CALL instruction would just | ||||||
|  | 		// obfuscate what's going on, since there is no CALL instruction. | ||||||
|  | 		switch r.Current.Fn.Name { | ||||||
| 		case "runtime.mstart", "runtime.systemstack_switch": | 		case "runtime.mstart", "runtime.systemstack_switch": | ||||||
| 			// these frames are inserted by runtime.systemstack and there is no CALL | 			// these frames are inserted by runtime.systemstack and there is no CALL | ||||||
| 			// instruction to look for at pc - 1 | 			// instruction to look for at pc - 1 | ||||||
| 			r.Call = r.Current |  | ||||||
| 		default: | 		default: | ||||||
| 			if r.Current.Fn != nil && it.pc == r.Current.Fn.Entry { | 			r.lastpc = it.pc - 1 | ||||||
| 				// if the return address is the entry point of the function that | 			r.Call.File, r.Call.Line = r.Current.Fn.cu.lineInfo.PCToLine(r.Current.Fn.Entry, it.pc-1) | ||||||
| 				// contains it then this is some kind of fake return frame (for example |  | ||||||
| 				// runtime.sigreturn) that didn't actually call the current frame, |  | ||||||
| 				// attempting to get the location of the CALL instruction would just |  | ||||||
| 				// obfuscate what's going on, since there is no CALL instruction. |  | ||||||
| 				r.Call = r.Current |  | ||||||
| 			} else { |  | ||||||
| 				r.lastpc = it.pc - 1 |  | ||||||
| 				r.Call.File, r.Call.Line, r.Call.Fn = it.bi.PCToLine(it.pc - 1) |  | ||||||
| 				if r.Call.Fn == nil { |  | ||||||
| 					r.Call.File = "?" |  | ||||||
| 					r.Call.Line = -1 |  | ||||||
| 				} |  | ||||||
| 				r.Call.PC = r.Current.PC |  | ||||||
| 			} |  | ||||||
| 		} | 		} | ||||||
| 	} else { |  | ||||||
| 		r.Call = r.Current |  | ||||||
| 	} | 	} | ||||||
| 	return r | 	return r | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user