keil调试过程查看全局变量和局部变量的方法及编译器优化

本文主要是介绍keil调试过程查看全局变量和局部变量的方法及编译器优化,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

keil调试过程查看全局变量和局部变量的方法及编译器优化

一、查看全局变量的方法:Watch Window

The Watch window allows to evaluate symbols, registers, and expressions. The window displays the item name, value, and type.
这里写图片描述Open this window through the toolbar button or using the menu View – Watch Windows.
这里写图片描述

Where

search boxAllows finding expressions within the current name list. The search string can consist of alphanumeric characters and mask characters as described in the appendix F. TR1 Search Expressions.
NameLists the expression name. Symbol names comply to the rules described in Program Variables (Symbols). Items are marked with an icon: Structure icon - identifies items of a complex type, such as structures or arrays. Simple icon - identifies items of a simple type, such as integers or characters.
ValueShows the memory address or the evaluated value of an expression. This field can contain explanatory text. Expressions of the type unsigned char show the value and the corresponding character. A single-quote () indicates that the value was restored from a previous debugging session. Values are updated: Whenever program execution stops. During program execution when View - Periodic Window Update is enabled. When clicking the Toolbox button Update Windows.
TypeShows the type of the expression. For functions the field shows the return and parameter types.

Using the Watch Window

Drag&drop expressions to other windows, for example to a Memory, Command, or Logic Analyzer window.

Add an Expression

  • Double-click the text and start editing. Refer to the section Expressions for details.
  • Drag&drop expressions from other windows into the Watch window.
  • Open the context menu of a file. Use Add item to - Watch #. The variable beneath the mouse position is added to the Watch window.
  • Use the command WatchSet in the window Command.

Remove an Expression

  • Click on the item name and press the Delete key.
  • Use the command WatchKill in the window Command.

Change the Value of an Expression

  • Click on the value-field and start editing. Not all expressions accept changes.

The context menu allows:

  • Removing an expression.
  • Changing the value representation.
  • Setting breakpoints.
  • Adding expressions to other windows.
  • Showing or hiding the toolbar that contains the search box.
二、查看局部变量的方法:Call Stack and Locals Window

The Call Stack + Locals window shows objects that are currently on stack. Tasks are shown for applications that use the RTX-RTOS. Each object is associated to its location or value, and type.

b_uv4_callstack_window[1]Open this window from the toolbar or using the menu View - Call Stack Window.

uv4_db_dbg_callstack[1]

Where

NameDisplays the symbol names. The currently active function or task is highlighted in green. Double-click the item node to expand or collapse the item.
Location/ValueDisplays the memory address or value of the item, or has an explanatory text. For items of the type unsigned char the field shows the value and the character.
TypeShows the object type. Functions are associated with their return type and parameter types.

The window content is updated automatically:

  • Whenever program execution stops.
  • During program execution when View - Periodic Window Update is enabled.

The context menu allows:

  • Jumping to the caller code.
  • Jumping to the callee code.
  • Switching between the hexadecimal and decimal representation of values.
三、编译器优化:Compiler optimization levels and the debug view

The precise optimizations performed by the compiler depend both on the level of optimization chosen, and whether you are optimizing for performance or code size.

The compiler supports the following optimization levels:

  • 0

    Minimum optimization. Turns off most optimizations. When debugging is enabled, this option gives the best possible debug view because the structure of the generated code directly corresponds to the source code. All optimization that interferes with the debug view is disabled. In particular: Breakpoints may be set on any reachable point, including dead code. The value of a variable is available everywhere within its scope, except where it is uninitialized. Backtrace gives the stack of open function activations which are expected from reading the source. Note Although the debug view produced by -O0 corresponds most closely to the source code, users may prefer the debug view produced by -O1 as this will improve the quality of the code without changing the fundamental structure. NoteDead code includes reachable code that has no effect on the result of the program, for example an assignment to a local variable that is never used. Unreachable code is specifically code that cannot be reached via any control flow path, for example code that immediately follows a return statement.

  • 1

    Restricted optimization. The compiler only performs optimizations that can be described by debug information. Removes unused inline functions and unused static functions. Turns off optimizations that seriously degrade the debug view. If used with --debug, this option gives a generally satisfactory debug view with good code density. The differences in the debug view from –O0 are: Breakpoints may not be set on dead code. Values of variables may not be available within their scope after they have been initialized. For example if their assigned location has been reused. Functions with no side-effects may be called out of sequence, or may be omitted if the result is not needed. Backtrace may not give the stack of open function activations which are expected from reading the source due to the presence of tailcalls. The optimization level –O1 produces good correspondence between source code and object code, especially when the source code contains no dead code. The generated code will be significantly smaller than the code at –O0, which may simplify analysis of the object code.

  • 2

    High optimization. If used with --debug, the debug view might be less satisfactory because the mapping of object code to source code is not always clear. The compiler may perform optimizations that cannot be described by debug information. This is the default optimization level. The differences in the debug view from –O1 are: The source code to object code mapping may be many to one, due to the possibility of multiple source code locations mapping to one point of the file, and more aggressive instruction scheduling. Instruction scheduling is allowed to cross sequence points. This can lead to mismatches between the reported value of a variable at a particular point, and the value you might expect from reading the source code. The compiler automatically inlines functions.

  • 3

    Maximum optimization. When debugging is enabled, this option typically gives a poor debug view. ARM recommends debugging at lower optimization levels. If you use -O3 and -Otime together, the compiler performs extra optimizations that are more aggressive, such as: High-level scalar optimizations, including loop unrolling. This can give significant performance benefits at a small code size cost, but at the risk of a longer build time. More aggressive inlining and automatic inlining. These optimizations effectively rewrite the input source code, resulting in object code with the lowest correspondence to source code and the worst debug view. The --loop_optimization_level=option controls the amount of loop optimization performed at –O3 –Otime. The higher the amount of loop optimization the worse the correspondence between source and object code. For extra information about the high level transformations performed on the source code at –O3 –Otime use the --remarks command-line option.

Because optimization affects the mapping of object code to source code, the choice of optimization level with -Ospace and -Otime generally impacts the debug view.

The option -O0 is the best option to use if a simple debug view is required. Selecting -O0 typically increases the size of the ELF image by 7 to 15%. To reduce the size of your debug tables, use the --remove_unneeded_entities option.

这篇关于keil调试过程查看全局变量和局部变量的方法及编译器优化的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/968052

相关文章

IDEA +maven git tomcat database数据库 调试 插件 log4j Spring junit

前言 idea优化配置、常规配置、配置maven、git、tomcat、database数据库、调试配置、插件配置、log4j配置、Spring配置等等,稍后一一更新! 优化配置(#item1 “item1”) 打开文件 :“idea – > bin – >idea64.exe.vmoptions” -Xms: 初始内存;-Xmx : 最大内存;-ReservedCodeCache

listview在拖动的时候背景图片消失变成黑色背景的原因及解决方法

listview在拖动的时候背景图片消失变成黑色背景的原因是:当我们不拖动的时候确实是显示你自己定义的背景色,但是当我们拖动的时候就变黑了,这是为什么呢?   因为在没有设置下,listview的默认背景是和系统窗口一样的黑色,我们拖动的时候listview的默认颜色(我的是黑色)覆盖了你自己定义的背景色,所以才显示的是黑色,而不是你自己定义的颜色。我们只需要把listview的背景色改变或者透明

去除appcompat_v7(第二种方法的补充)

当我们创建新的Android项目移除 create Activity前的选项框,通过这样做,eclipse将不会自动引用这个库项目“appcompat_v7”。然后你可以手动地创建主活动。但是如果你有fragment和actionbar这些控件时注意一定要引用。  之前的方式请   点击这里 !!!

iOS 延迟执行的几种方法

1、performSelector方法 - (void)viewDidLoad {[super viewDidLoad];NSLog(@"当前时间:%@",[NSDate date]);[self performSelector:@selector(delayMenthod) withObject:nil afterDelay:2.0];}- (void)delayMenthod{NSLog(

iOS逆向 查看ipa包是否加密

从appstore上下载的ipa包,都是经过苹果公司加了密的,我们做逆行开发首先就需要把ipa加密的壳给砸掉,砸壳之后我们如何查看是否砸壳成功呢? 微信砸壳之后的文件为:WeChat.decrypted 打开终端,进入到WeChat.decrypted所在的目录,然后输入命令行: otool -l WeChat.decrypted | grep crypt cryptid 1代表加密,

iOS逆向 实时查看手机日志

一、第一种方法:使用tail命令查看 用SSH 连接手机之后,可以使用tail 命令查看越狱手机的实时日志。但是tail不能直接使用,需要先在手机上装两个插件。 1、在Cydia搜索“syslogd to/var/log/syslog”并安装; 2、在Cydia搜索“Core Utilities”并安装; 比如查看微信的日志: yuancande-iPhone:~ root# tail

dpkg: status database area is locked by another process 解决方法

解决办法:sudo rm -rf /var/lib/dpkg/lock 或者:rm -rf /var/lib/dpkg/lock

iOS逆向 免密码连接手机调试

iOS逆向开发交流群 用SSH远程连接手机的时候,终端会多次提醒用户输入密码,这个比较麻烦,默认的秘密为:alpine 。如果需要反复调试,那么每次要求输入密码,显然很麻烦。下面介绍一种不需要输入密码,直接远程登录手机调试的方法。 大概的思路:在电脑上生成公钥,然后将公钥拷贝到你需要调试的越狱手机中。这样,你的电脑就被手机信任了。以后通过这台电脑远程连接手机,就不需要输入密码了。 一、配

iOS 加载大量本地视频优化

一、问题的产生 1.1 发现问题 最近开发了一个视频剪辑的APP,其中有这么一个功能,对原视频进行剪辑编辑好之后,可以直接导出到相册,同时APP也会将这个视频保存到本地(沙盒),然后APP专门有一个“我的作品”界面来展示所有存储在本地的视频。在自己做测试的时候,发现点击“我的作品”页面,需要比较长的时间才能响应,而且视频越多响应时间越长。于是我猜想可能是因为同时加载大量视频导致的。 1.2

Android中切换到主线程更新方法

方法一: view.post(Runnable action) 在子线程中更新UI textView.post(new Runnable() {@Overridepublic void run() {textView.setText("更新textView");}}); 如果你的子线程里可以得到要更新的view的话,可以用此方法进行更新。 view还有一个方法view.postDel