-
Notifications
You must be signed in to change notification settings - Fork 3k
Unify fault handling and add script to show faults #5847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Triggering a 'morph build' to find the targets which are not defining HardFault_Handler with WEAK attribute. |
/morph build |
Build : FAILUREBuild number : 860 |
Couple of them failed. @SenRamakri Shall we fix those targets ? |
|
||
fault_print_str("\n\n-- MbedOS Fault Handler --\n\n",NULL); | ||
|
||
/* Just spin here, we have alrady crashed */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alrady
-> already
fault_print_str("\n++ MbedOS Fault Handler ++\n\nFaultType: ",NULL); | ||
|
||
switch( fault_type ) { | ||
case HARD_FAULT_EXCEPTION: fault_print_str("HardFault",NULL); break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
each statement own line
#define BUS_FAULT_EXCEPTION (0x30) | ||
#define USAGE_FAULT_EXCEPTION (0x40) | ||
|
||
__NO_RETURN void mbed_fault_handler (uint32_t fault_type, void *mbed_fault_context_in, void *osRtxInfoIn); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func documentation missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add some documentation here, but note that this is not a public API, so its not expected to be called anyone else part from the Fault handlers. So, I'll add some non-doxygen comments.
@@ -0,0 +1,266 @@ | |||
#!/usr/bin/env python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
license addition here
|
||
def file_name_for_function_name(self, funcname): | ||
for eachline in self.maplines: | ||
#print("%s:%s"%(eachline,funcname)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dead code should be removed in this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review, and will fix the comments. After some discussion here and getting some feed backs, I'm going to make this a build time enabled feature. We will also make this depend on if TARGET_CORTEX_M is defined so that it doesn't fail on Cortex-A targets.
4480b9d
to
9529da0
Compare
/morph build |
Build : FAILUREBuild number : 981 |
/morph build |
Build : FAILUREBuild number : 983 |
211cd35
to
f5bdab9
Compare
@@ -3575,7 +3575,7 @@ | |||
} | |||
}, | |||
"inherits": ["Target"], | |||
"macros": ["CMSIS_VECTAB_VIRTUAL", "CMSIS_VECTAB_VIRTUAL_HEADER_FILE=\"cmsis_nvic.h\""], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already enable other features like MBED_HEAP_STATS_ENABLED, MBED_STACK_STATS_ENABLED, MBED_TRAP_ERRORS_ENABLED on this platform for testing. So disabling mbed-os hardfault handler feature as this target is limited on ram/rom.
@@ -3613,7 +3613,7 @@ | |||
"inherits": ["Target"], | |||
"detect_code": ["4600"], | |||
"extra_labels": ["Realtek", "AMEBA", "RTL8195A"], | |||
"macros": ["__RTL8195A__","CONFIG_PLATFORM_8195A","CONFIG_MBED_ENABLED","PLATFORM_CMSIS_RTOS"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
REALTEK_AMEBA provides their own implementation of HardFault handler as binary. So, disabling Mbed-OS fault handling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the details, they should be part of the commit message to have them available not only on github
MBED_FAULT_HANDLER_DISABLED
vs CONFIG_MBED_ENABLED
(enabled or disabled might be confusing, so one of these should be fixed?). Can we have this fault handler enabled by default, and only removed if not used (first comes to my mind using Target from targets to define it , or another way to do this) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xc0170 - Yes, Currently this is enabled by default and is disabled only if you specify MBED_FAULT_HANDLER_DISABLED flag. targets.json can be used to disable this on specific targets if not required. I think that matches your expectations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SenRamakri Could you make this configurable through the configuration system? Currently it's a macro, and we would like to eliminate macros going forward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{
"name": "rtos",
"config": {
"present": 1,
"detailed-fault-handler": {
"help": "Configures the detail of the fault handler",
"value": true
}
},
"target_overrides" : {
"K64F": {
"detailed-fault-handler": false
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xc0170 - Looks like we cannot use Json based config system for this as the Config defines are not visible in .S files for IAR toolchain. @theotherjimmy and I tried to work through this but couldn't really make it work for IAR due to some differences in how IAR preprocessing works. So, reverting back to old mechanism, unfortunately.
@@ -0,0 +1,278 @@ | |||
#!/usr/bin/env python | |||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
License added
/morph build |
Build : SUCCESSBuild number : 985 Triggering tests/morph test |
Test : SUCCESSBuild number : 806 |
Exporter Build : SUCCESSBuild number : 676 |
/morph uvisor-test |
Any comments @sg- @c1728p9 @studavekar? |
@SenRamakri, thank you for your changes. You should get some feedback from the following people shortly: @bulislaw @ARMmbed/team-st-mcd @c1728p9 @pan- @mbed-os-maintainers @theotherjimmy @scartmell-arm @ARMmbed/team-onsemi please review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please let me know if you want help with any of this!
|
||
from __future__ import print_function | ||
from os import path | ||
import re, bisect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you split this import into two lines to match the style throughout the rest of the tools?
NM_EXEC = "arm-none-eabi-nm" | ||
OPT = "-nlC" | ||
ptn = re.compile("([0-9a-f]*) ([Tt]) ([^\t\n]*)(?:\t(.*):([0-9]*))?") | ||
fnt = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is reassigned on the next line. Please delete this line.
#arm-none-eabi-nm -nl <elf file> | ||
NM_EXEC = "arm-none-eabi-nm" | ||
OPT = "-nlC" | ||
ptn = re.compile("([0-9a-f]*) ([Tt]) ([^\t\n]*)(?:\t(.*):([0-9]*))?") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be uppercase, and start with an underscore. That would indicate that it's a private global variable.
import sys | ||
|
||
#arm-none-eabi-nm -nl <elf file> | ||
NM_EXEC = "arm-none-eabi-nm" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we don't support ARM or IAR here, do we?
else: | ||
return toks[-1] | ||
|
||
def parseHFSR(hfsr): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function both parses and prints. Maybe a different name is in order.
|
||
p = args.elfpath | ||
m = args.mappath | ||
i = args.input |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use one letter variable names. They're hard to follow.
|
||
# specify arguments | ||
parser.add_argument('-i','--input', metavar='<path to input file with crash log output>', type=str, | ||
help='path to input file') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is an input file? Please give the format for this file type.
parser.add_argument('-e','--elfpath', metavar='<module or elf file path>', type=str, | ||
help='path to elf file') | ||
parser.add_argument('-m','--mappath', metavar='<map file path>', type=str, | ||
help='path to map file') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The three prior arguments are all required. Help the user by adding required=True
to each of the add_argument
calls.
Further they're all files, so please use FileType
as the type instead of str
, which is the defualt.
if not path.exists(i): | ||
print("Input crash log path %s does not exist"%(str(i))) | ||
parser.print_usage() | ||
sys.exit(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These prior 4 checks will all be eliminated by the use of FileType
as described above.
print("Inputs:") | ||
print("\tCrash Log: %s"%(i)) | ||
print("\tElf Path: %s"%(p)) | ||
print("\tMap Path: %s"%(m)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wonderful for debugging the script, but useless to the user. Please remove these prints.
@SenRamakri Your title seems to have slipped off the maximum length. Let me get that for you. |
91ccce7
to
857ee13
Compare
Test : SUCCESSBuild number : 832 |
Exporter Build : SUCCESSBuild number : 708 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last nit
return funcname | ||
|
||
def print_HFSR_info(hfsr): | ||
if hfsr != 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you drop this line please?
8ebbcd4
to
bc43459
Compare
@theotherjimmy Does this latest commit mean you're review is now all good? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like these fixed, but I'm not going to block this on 2 small style nits.
else: | ||
print("\t\tProcessor Arch: ARM-V7M or above") | ||
|
||
print("\t\tProcessor Variant: %X"%((int(cpuid,16) & 0xFFF0 ) >> 4)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a space on each side of the %
?
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you reduce the number of extra lines at the end of the file to 1?
Thanks @SenRamakri for this feature looks good! crash_log_parser.py utility is really helpful to quickly decode the crash 👍 |
/morph build |
Build : FAILUREBuild number : 1118 |
Build failure is due to a new device being introduced since the last rebase. Rebasing the PR should fix the issue. |
…eview/other fixes
bc43459
to
19ad4e2
Compare
/morph build |
Build : SUCCESSBuild number : 1121 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 798 |
Test : SUCCESSBuild number : 926 |
This change set adds support for generating core/register/thread information dump on fault exceptions which helps debugging fault exceptions.
Various fault scenarios has been used to test the core dump generation( See a sample app at https://github.com/SenRamakri/mbed-os-example-fault-handler which generate various exceptions ).
A python script has also been added( crash_log_parser.py ) which can parse the crash dump info and generate more detailed information on the crash using .elf/.map files. See the README.md as part of tools/debug_tools/crash_log_parser for usage of the script.
Also note that assembly files have been kept common for ARMv6M, v7M , v8M cores. Although some of the exceptions defined in assembly files like MemManage/UsageFault/BusFault are not used for some v6M cores, it doesn't cause any issues and helps to keep the code common. Also note that code to check for whether FP context is saved is benign for non-FP cores since bit-4 in LR is defined as SBOP(reads as 1 as we want) for non-FP cores.