| 249 | } |
| 250 | |
| 251 | void TracePC::SetFocusFunction(const std::string &FuncName) { |
| 252 | // This function should be called once. |
| 253 | assert(!FocusFunctionCounterPtr); |
| 254 | // "auto" is not a valid function name. If this function is called with "auto" |
| 255 | // that means the auto focus functionality failed. |
| 256 | if (FuncName.empty() || FuncName == "auto") |
| 257 | return; |
| 258 | for (size_t M = 0; M < NumModules; M++) { |
| 259 | auto &PCTE = ModulePCTable[M]; |
| 260 | size_t N = PCTE.Stop - PCTE.Start; |
| 261 | for (size_t I = 0; I < N; I++) { |
| 262 | if (!(PcIsFuncEntry(&PCTE.Start[I]))) continue; // not a function entry. |
| 263 | auto Name = DescribePC("%F", GetNextInstructionPc(PCTE.Start[I].PC)); |
| 264 | if (Name[0] == 'i' && Name[1] == 'n' && Name[2] == ' ') |
| 265 | Name = Name.substr(3, std::string::npos); |
| 266 | if (FuncName != Name) continue; |
| 267 | Printf("INFO: Focus function is set to '%s'\n", Name.c_str()); |
| 268 | FocusFunctionCounterPtr = Modules[M].Start() + I; |
| 269 | return; |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | Printf("ERROR: Failed to set focus function. Make sure the function name is " |
| 274 | "valid (%s) and symbolization is enabled.\n", FuncName.c_str()); |
| 275 | exit(1); |
| 276 | } |
| 277 | |
| 278 | bool TracePC::ObservedFocusFunction() { |
| 279 | return FocusFunctionCounterPtr && *FocusFunctionCounterPtr; |