-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
arch/x86_64:Add FP backtrace function
Signed-off-by: liwenxiang1 <[email protected]>
- Loading branch information
1 parent
5a4d31f
commit a5bc9a9
Showing
9 changed files
with
202 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
/**************************************************************************** | ||
* arch/x86_64/src/intel64/intel64_backtrace_fp.c | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. The | ||
* ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Included Files | ||
****************************************************************************/ | ||
|
||
#include <nuttx/config.h> | ||
|
||
#include <nuttx/arch.h> | ||
|
||
#include "sched/sched.h" | ||
|
||
#include <x86_64_internal.h> | ||
|
||
/**************************************************************************** | ||
* Pre-processor Definitions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Name: backtrace | ||
* | ||
* Description: | ||
* backtrace() parsing the return address through frame pointer | ||
* | ||
****************************************************************************/ | ||
|
||
nosanitize_address | ||
static int backtrace(uintptr_t *base, uintptr_t *limit, | ||
uintptr_t *rbp, uintptr_t *rip, | ||
void **buffer, int size, int *skip) | ||
{ | ||
int i = 0; | ||
|
||
if (rip) | ||
{ | ||
if ((*skip)-- <= 0) | ||
{ | ||
buffer[i++] = rip; | ||
} | ||
} | ||
|
||
for (; i < size; rbp = (uintptr_t *)(*rbp)) | ||
{ | ||
if (rbp > limit || rbp < base || | ||
*(uintptr_t *)rbp == 0) | ||
{ | ||
break; | ||
} | ||
|
||
if ((*skip)-- <= 0) | ||
{ | ||
buffer[i++] = (uintptr_t *)(*(rbp + 1)); | ||
} | ||
} | ||
|
||
return i; | ||
} | ||
|
||
/**************************************************************************** | ||
* Public Functions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Name: up_backtrace | ||
* | ||
* Description: | ||
* up_backtrace() returns a backtrace for the TCB, in the array | ||
* pointed to by buffer. A backtrace is the series of currently active | ||
* function calls for the program. Each item in the array pointed to by | ||
* buffer is of type void *, and is the return address from the | ||
* corresponding stack frame. The size argument specifies the maximum | ||
* number of addresses that can be stored in buffer. If the backtrace is | ||
* larger than size, then the addresses corresponding to the size most | ||
* recent function calls are returned; to obtain the complete backtrace, | ||
* make sure that buffer and size are large enough. | ||
* | ||
* Input Parameters: | ||
* tcb - Address of the task's TCB | ||
* buffer - Return address from the corresponding stack frame | ||
* size - Maximum number of addresses that can be stored in buffer | ||
* skip - number of addresses to be skipped | ||
* | ||
* Returned Value: | ||
* up_backtrace() returns the number of addresses returned in buffer | ||
* | ||
* Assumptions: | ||
* Have to make sure tcb keep safe during function executing, it means | ||
* 1. Tcb have to be self or not-running. In SMP case, the running task | ||
* PC & SP cannot be backtrace, as whose get from tcb is not the newest. | ||
* 2. Tcb have to keep not be freed. In task exiting case, have to | ||
* make sure the tcb get from pid and up_backtrace in one critical | ||
* section procedure. | ||
* | ||
****************************************************************************/ | ||
|
||
int up_backtrace(struct tcb_s *tcb, | ||
void **buffer, int size, int skip) | ||
{ | ||
struct tcb_s *rtcb = running_task(); | ||
int ret; | ||
|
||
if (size <= 0 || !buffer) | ||
{ | ||
return 0; | ||
} | ||
|
||
if (tcb == NULL || tcb == rtcb) | ||
{ | ||
if (up_interrupt_context()) | ||
{ | ||
#if CONFIG_ARCH_INTERRUPTSTACK > 3 | ||
void *istackbase = (void *)up_get_intstackbase(this_cpu()); | ||
|
||
ret = backtrace(istackbase, | ||
istackbase + IRQ_STACK_SIZE, | ||
(void *)__builtin_frame_address(0), | ||
NULL, buffer, size, &skip); | ||
#else | ||
ret = backtrace(rtcb->stack_base_ptr, | ||
rtcb->stack_base_ptr + rtcb->adj_stack_size, | ||
(void *)__builtin_frame_address(0), | ||
NULL, buffer, size, &skip); | ||
#endif /* CONFIG_ARCH_INTERRUPTSTACK > 3 */ | ||
if (ret < size) | ||
{ | ||
ret += backtrace(rtcb->stack_base_ptr, | ||
rtcb->stack_base_ptr + rtcb->adj_stack_size, | ||
(void *)up_current_regs()[REG_RBP], | ||
(void *)up_current_regs()[REG_RIP], | ||
&buffer[ret], size - ret, &skip); | ||
} | ||
} | ||
else | ||
{ | ||
ret = backtrace(rtcb->stack_base_ptr, | ||
rtcb->stack_base_ptr + rtcb->adj_stack_size, | ||
(void *)__builtin_frame_address(0), | ||
NULL, buffer, size, &skip); | ||
} | ||
} | ||
else | ||
{ | ||
ret = backtrace(tcb->stack_base_ptr, | ||
tcb->stack_base_ptr + tcb->adj_stack_size, | ||
(void *)tcb->xcp.regs[REG_RBP], | ||
(void *)tcb->xcp.regs[REG_RIP], | ||
buffer, size, &skip); | ||
} | ||
|
||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters