1. Your Situation
You find yourself debugging a Java app with Eclipse and you’re stepping through the code in the Debug perspective. You have the Variables view open and for most of the selected types you can see a reasonable toString() output below the variables list.
However, many types don’t have a type specific implementation of toString(). E.g., consider an array of objects. There’s no toString() on arrays. That’s why the variables view prints you some meaningless default text with a hashcode for such variables.
But did you know that you can change that by defining a custom toString() implementation that’s used by the variables view at runtime? Let me introduce you to the concept of Detail Formatters and learn about the Display view along the way, too.
2. Preparing a custom type evaluation
Lets start at a breakpoint in some arbitrary code as shown in the following screenshot. The debugger stopped within a for-loop that iterates over a collection of CellBindDesc elements. In the Variables view the variable desc is selected to see what’s inside. Unfortunately, the class CellBindDesc didn’t override toString(). That’s why the default gibberish is printed below the variables list .
You do not need to know all the details about the CellBindDesc. It’s enough to know that it’s a description of mapping a model element’s field to an uiElement, e.g. a String property to a Text field.
To find a specific field of a model element the CellBindDesc holds an array of model element properties that’s similar to a tree path. The first element is a reference to a property of the model root element that’s stored in the model field of CellBindDesc. The other elements are references to properties of the model tree.
So, what I actually want to see below the variables list is not the gibberish, but at least the path to the model property and a hint to which uiElement it is bound. Sounds like some StringBuilder code, right? To create and test this code on the fly you should open the Display view . Imagine this view as being a container of code statements that are inlined at the position of the current debug step. In case of the screenshot above that would be line 170.
But the code is not really inlined. Instead you can use the Inspect command to execute the selected statements at that debug step. You can run that command with [Ctrl]+[Shift]+[I].
As you can see in the screenshot all lines are selected and the last statement even is a return statement that concatenates stuff to a String. Running [Ctrl]+[Shift]+[I] on that selection will show the familiar Inspect popup containing a String node with the return value if you did it right.
As you can see in this example, the Display view is very powerful. It’s so important to me, that I always open it when debugging. By the way, code completion does work there, too.
3. Edit the Detail Formatter
Now, with the snippet being tested in the Display view and the result being what one would actually like to see at it’s time to configure the Detail Formatter. Open the context menu on the variable for which you wish to configure a Detail Formatter and select the Edit Detail Formatter…entry .
In the Edit Detail Formatter dialog paste the snippet from the Display view and make sure the Detail Formatter is enabled.
After closing the dialog you should see the detail formatted output of your selected variable. In case of my example I’m now able to see the type, the model path and the ui element of each CellBindDesc directly below the variables list.
As the Detail Formatter is used for every instance of the type on which it is defined I am now able to step through the list via [F8]. No more need to check each property of the variable desc until I know all the values I need to tell if something is wrong. Ain’t that a great time safer? I bet it is!
4. Happy Debugging
Things you should have learned:
- Always open the Display view when you’re in the Debug perspective and make use of it. You can even collect several statements there and select only the one(s) you need for inspection depending on your debug context.
- Write Detail Formatters for arrays and complex types to show more details in the Variables view. Detail Formatters do even override toString() implementations if there should be one!
Happy debugging!
相关推荐
《S7_200中文实例Tips&tricks》是一个针对西门子S7-200系列PLC(可编程逻辑控制器)的实用技巧和经验分享集合。S7-200是西门子公司推出的一款小型PLC,广泛应用于自动化控制领域,尤其在中小型制造业中,因其小巧、...
S7_200中文实例Tips&tricks.zip西门子PLC编程实例程序源码下载S7_200中文实例Tips&tricks.zip西门子PLC编程实例程序源码下载S7_200中文实例Tips&tricks.zip西门子PLC编程实例程序源码下载S7_200中文实例Tips&tricks....
标题中的“工业机器人-S7_200中文实例Tips&tricks.7z”表明这是一个与工业机器人编程相关的资源包,特别提到了S7-200系列,这是西门子自动化产品线中的一款知名小型PLC(可编程逻辑控制器)。这个资源很可能是为了...
《S7_200中文实例Tips&tricks》是一个针对西门子S7-200系列PLC编程的实用资源集合。S7-200是西门子推出的一种小型可编程逻辑控制器,广泛应用于工业自动化领域,尤其适合中小型控制系统。这个压缩包中的内容可能是由...
此压缩包"西门子PLC程序源码-S7_200中文实例Tips&tricks.zip"包含了针对该型号PLC的程序源码和中文实例,旨在帮助用户更好地理解和掌握S7-200的编程技巧。 1. **S7-200 PLC概述**: S7-200 PLC是一款紧凑型、高...
### DirectX 9 Tips and Tricks详解 #### 一、概述 《ShaderX2:Shader Programming Tips & Tricks with DirectX 9》是一本由Wolfgang F. Engel编辑的专业书籍,由Wordware Publishing出版。本书主要介绍了使用...
西门子PLC例程源码S7_200中文实例Tips&tricks本资源系百度网盘分享地址
《Wordware Publishing - LightWave 3D 8.1001 Tips & Tricks》是一部针对LightWave 3D 8版本的专业指南,旨在帮助用户掌握并优化这款强大的三维动画和建模软件的使用技巧。LightWave 3D是由NewTek公司开发的一款...
Tips and Tricks to Improve CNN-based Chest X-ray Diagnosis A Survey.zip
这个名为“西门子PLC例程-S7_200中文实例Tips&tricks.zip”的压缩包文件,显然是为用户提供了一系列关于S7-200 PLC的中文实例和实用技巧。 在学习和应用西门子S7-200 PLC时,理解其基本结构和工作原理至关重要。S7-...
Best practice and tips & tricks to write scientific papers in LaTeX, with figures generated in Python or Matlab.zip
Pandas-Tips-Tricks-and-Best-Practices-main
S7-200系列是西门子推出的一款小型可编程逻辑控制器(PLC),广泛应用于工业自动化领域。这款控制器以其紧凑的体积、强大的功能和易用性著称。本文将深入探讨S7-200的使用技巧,帮助用户更高效地进行系统设计、编程...
本书《Wordware ShaderX Shader Programming Tips & Tricks with DirectX 9》特别关注在DirectX 9环境下进行Shader编程的技巧和策略。它涵盖了从基础到高级的各种主题,如像素着色器、顶点着色器、光照模型、纹理...
首先请记住,这不是 MATLAB 教程。 这只是我在编写 MATLAB Central 存储库中可用的工具箱时发现有用的技巧列表。 如果您对这些代码段有任何更正,或者您想在本文档中描述的内容中添加您自己的提示,您可以给我发送...
使用Keras的编程技巧 Keras-Tips-Tricks-and-Techniques-master.zip
提供了适用于实际生活中的秘诀和方法(tips and tools),运用这些方法能使你的大脑能够超常工作,让你成为更好的思想者。在当今快速发展的信息经济时代,管理你的生活需要开发你的大脑的潜能。《心理和脑与生活:训练...
Shuffle: Tips and Tricks Julien Demouth, NVIDIAhttp://www.gputechconf.com/page/home.htmlGlossary Warp— Implicitly synchronized group of threads (32 on current HW) Warp ID (warpid)— Identifier ...