`
rensanning
  • 浏览: 3548806 次
  • 性别: Icon_minigender_1
  • 来自: 大连
博客专栏
Efef1dba-f7dd-3931-8a61-8e1c76c3e39f
使用Titanium Mo...
浏览量:38151
Bbab2146-6e1d-3c50-acd6-c8bae29e307d
Cordova 3.x入门...
浏览量:607316
C08766e7-8a33-3f9b-9155-654af05c3484
常用Java开源Libra...
浏览量:682345
77063fb3-0ee7-3bfa-9c72-2a0234ebf83e
搭建 CentOS 6 服...
浏览量:89357
E40e5e76-1f3b-398e-b6a6-dc9cfbb38156
Spring Boot 入...
浏览量:401860
Abe39461-b089-344f-99fa-cdfbddea0e18
基于Spring Secu...
浏览量:69697
66a41a70-fdf0-3dc9-aa31-19b7e8b24672
MQTT入门
浏览量:91724
社区版块
存档分类
最新评论

在Titanium Studio中调试JavaScript

阅读更多

【官方地址】https://wiki.appcelerator.org/display/guides/Debugging+in+Titanium+Studio

 

 

Objective

 

In this section, you will learn how to debug your Titanium applications using the tools provided by Titanium Studio. You'll learn how to use the Debug perspective, how to set breakpoints, run a project in debug mode, and how to step into, over, and return from functions.

Contents

So far in this chapter, we've looked at print tracing (logging) and crash log analysis. Titanium Studio supports breakpoint testing, which lets you evaluate the state and values of variables during the execution of your program.You can set breakpoints at specific locations in your code. Or, you can use an exception breakpoint to pause your program when a specified exception is raised.

To see how this works, we'll need to look at these topics:

  • Running a program in debug mode
  • Titanium Studio's Debug perspective
  • Setting breakpoints
  • Stepping into, through, and over breakpoints and examining the stack trace

Running a program in debug mode

To use Studio's debugging tools, you'll need to run your app in Debug mode. You can do so in either the iOS Simulator or Android emulator, but not on a physical device. As shown in the following screenshot, click the Debug menu and choose the appropriate target.

Debug perspective

The Debug perspective contains several views that are not found in the Web perspective:

  • Debug View - The Debug View displays debugging targets and processes that are currently running.
  • Variables View - The Variables View shows the scope of variables when the JavaScript thread is suspended.
  • Breakpoints View - The Breakpoints View lists the breakpoints for the file that you are debugging.
  • Scripts View - The Scripts View displays the scripts that are currently being debugged.
  • Expressions View - The Expressions View displays the value of current expressions.

In addition to the above debugging-specific views, you will also have access to some views from the Web perspective that you are probably familiar with:

  • Editor - The Editor area displays the file currently being debugged in its appropriate Editor.
  • Outline View - The Outline View displays an outline of the code for the file that is currently being debugged.
  • Console View - The Console View displays log output from the debugger.

These are labeled in the following diagram.

Studio will display the Debug perspective automatically when you run a project in debug mode and a breakpoint is encountered. You can manually switch to the Debug perspective by clicking the Perspective button in the upper-right corner of the workbench. (Click the corresponding "Web" button to switch back to the normal code-editing perspective.)

Setting breakpoints

Breakpoints are locations within your app where execution will pause, giving you the opportunity to examine variable state and values. Code execution is paused at the moment immediately before the marked line of code is executed. Any breakpoints you set will be hit when the app loads (or if they are in event listeners or separate files, when those execute). Some other things you can do:

  • Edit Variables by clicking their values while inside a breakpoint.
  • Add Expressions to the Expressions view to see the value of free form JS code.
  • Set conditions on breakpoints by going to the "Breakpoints" view, right clicking on the breakpoint, clicking on "Properties", and hit the checkmark next to "Enable Condition"
  • Click on various frames in the stack trace to see values of other variables in your call stack.

Setting manual breakpoints

A manual, or explicit, breakpoint marks a specific line of code within your application at which execution should pause. You set these yourself by either:

  • Double-clicking in the margin in the Editor's code view, or,
  • Right-clicking the margin and choosing Toggle Breakpoint from the context menu.

Setting exception breakpoints

An exception breakpoint causes your app to pause when an exception is raised that meets the criteria you specify. Such breakpoints are not associated with a particular line of code in your app. To add a breakpoint to your code so that execution automatically breaks on a certain type of exception:

  1. Open the file with your script in the appropriate Editor.
  2. From the Run menu, select Add JavaScript Exception Breakpoint... to open the Add JavaScript Exception Breakpoint dialog box.
  3. On the Add JavaScript Exception Breakpoint pop-up window, select the type of exception that you would like to break on.
  4. Run the app in debug mode. If the exception is thrown, your app will pause and Studio will switch to the Debug perspective.

To remove an exception breakpoint:

  1. Switch to the Debug perspective, if necessary.
  2. Display the Breakpoints view, which will list the current breakpoints in your app. 
  3. Then, take one of the following actions:
    • Right-click the breakpoint and choose Disable, Remove, or Remove All breakpoints.
    • With the breakpoint selected, use the associated toolbar buttons to Disable, Remove, or Remove All breakpoints. 

Stepping Through Code

Stepping through code is a common debugging technique that lets you examine your code's operation line by line. Studio supports three types of stepping: Step Into, Step Over, and Step Return. Studio provides various buttons in the Debug perspective to make it easy to step through your code:

Button Name When you click ...
Step Into If set before a function call, execution will move to the first line of the function then stop. If set before a statement, execution will proceed until the next breakpoint (if one is set).
Step Over Studio will execute the function then stop on the next line in your app.
Step Return When you've Stepped Into a function, execution will finish in the current function, then return you to the spot where you went into the function, then pause again.
Resume Execution will resume; it will stop at the next breakpoint (if one is set).
Terminate Execution of your app will terminate.

If you set a breakpoint at a Titanium function that invokes native code, that function is treated as a single statement. Thus, Step Into and Step Over will do the same thing: execute the function then stop on the next line.

Variables view

The Variables View (shown below) displays current stack frame variables and their values. It is available in the Debug perspective while your app is paused at a breakpoint.

To change the value of a variable, when paused at a breakpoint:

  1. In the Variables View, expand or collapse the variables hierarchy as necessary to display the relevant variable.
  2. Click the current value (in the Value column).
  3. Enter the new value and press Return (or Enter)

Alternatively,

  1. Right-click the variable that you want to change, and choose Change Value... from the context menu to open the Set Value dialog box.
  2. Enter the new value for your variable.
  3. Click OK.

Viewing error messages in the console

In most cases, error messages that cause your app to crash will be displayed in the Console pane of the Web perspective. Occasionally, all you'll see is a simple message like "Application terminated" especially when building for iOS. In those cases, you can sometimes get more detailed information from the Debug perspective.

  1. When the app has crashed, switch to the Debug perspective.
  2. In the Debug pane, click the "exit value: -1" line, typically the last one.
  3. More detailed log output should then be visible in the Console pane.

Titanium Studio build log

Titanium Studio maintains a log of messages output during your project build processes. Each time you build a project, the messages are appended to the .log file. You can view this file by choosing HelpTitanium StudioView Log File. The log file is opened in the editor perspective just like any other code file, oldest entries are listed first. Occasionally, you should clear out this file so it doesn't grow too large. Choose Help,Titanium StudioClear Log File to do so.

分享到:
评论

相关推荐

    Titanium环境搭建

    在Titanium Studio中,你可以利用其内置的模拟器或连接实际设备进行应用的调试和测试。 请注意,随着软件更新,这些下载链接和具体步骤可能会有所变化。建议定期检查官方网站获取最新的安装包和指南,以确保开发...

    TITANIUM智能手机应用开发教程

    - 使用TITANIUM Studio或Chrome开发者工具进行调试。 6. **发布应用**: - 构建针对不同平台的应用包。 - 提交至Apple App Store和Google Play商店。 #### 四、TITANIUM与其他移动开发框架对比 - **React ...

    cuacfm-ios-appcelerator-iphone:适用于iOS的CUAC FM应用程序,使用Titanium Appcelerator在javascript中制作

    在Appcelerator Titanium中,开发者可以利用丰富的JavaScript库和框架,如jQuery或React,来实现复杂的功能。 2. Titanium API:Titanium提供了一套完整的API,覆盖了设备的各种功能,包括音频播放、网络通信、用户...

    TitaniumMobile开发跨平台iOS和Android应用

    4. **强大的IDE:** Titanium Studio提供了全面的开发环境,包括代码编辑、调试工具以及构建和发布功能。 5. **原生性能:** 尽管使用Web技术开发,但Titanium Mobile仍能实现接近原生应用的性能。 **劣势:** 1. ...

    VFW-Examples:福赛大学 VFW 学生的课堂示例

    在 Titanium 开发中,JavaScript 用于构建原生的移动应用,这得益于 Titanium 提供的 API,它允许开发者使用 JavaScript 访问和控制设备的硬件功能,如摄像头、GPS、传感器等。 【详细知识点】 1. **Titanium ...

    DynamicApp:Titanium应用程序生成随机代码+命令注入器

    在Titanium框架中,JavaScript不仅用于界面交互,还用于实现复杂的业务逻辑和数据操作。在动态代码生成和命令注入的场景下,理解JavaScript的变量、函数、对象和闭包等概念至关重要。 5. **安全注意事项**: 开发...

    learning-titanium

    在 "learning-titanium-master" 文件中,你将找到一系列关于 Titanium 学习的资源,可能包括教程文档、示例代码、练习项目等,它们将帮助你深入理解 Titanium 开发,并提升实际操作能力。通过这个学习过程,你可以...

    program_with_appcelerator_titanium:如果你做到了,你就会明白! 钛移动编程SDK3兼容学习

    在IT行业中,Appcelerator Titanium 是一款非常知名的跨平台移动应用开发框架,它允许开发者使用JavaScript语言来构建原生的iOS、Android以及Windows Phone应用程序。本篇将详细讲解使用Appcelerator Titanium SDK 3...

    learning-titanium:第一个学习钛的应用程序

    完成编码后,可以在 Titanium Studio 或 CLI 中运行应用到模拟器或真实设备上进行测试。Titanium 提供了实时预览和调试工具,帮助开发者快速定位和解决问题。 **8. 发布应用** 一旦应用开发完成并经过充分测试,...

    企业级IT架构分享 云计算架构师成长之路 Titanium的企业级应用-原生UI局限性和跨平台的折中 共37页.pdf

    在实际开发过程中,使用**Titanium Studio**创建module项目,并借助**Eclipse**进行具体的开发工作。此外,还需要利用**Android NDK**将C/C++源文件编译成本地库,以实现与Titanium的适配。通过这种方式,可以有效地...

    vscode-perl-debug:寻找维护者。 用于Visual Studio代码的Perl调试器扩展

    在编程领域,调试是至关重要的一个环节,它允许开发者识别并修复代码中的错误。Visual Studio Code(VSCode)作为一款广受欢迎的源代码编辑器,拥有丰富的插件生态,其中就包括针对各种语言的调试器。"vscode-perl-...

    titanium:MobGeek Titanium 4 周课程代码

    4. **Titanium Studio**:集成开发环境(IDE),集成了代码编辑、调试、预览和打包等功能,为开发者提供了高效的工作流。 5. **社区支持**:钛合金拥有活跃的开发者社区,提供丰富的开源模块和示例代码,方便开发者...

    TiAttendance

    9. **错误处理和调试**:在开发过程中,设置适当的错误处理机制和日志记录,以便快速定位和解决问题。 10. **性能优化**:学习如何优化代码,减少内存占用,提高应用启动速度和运行效率,尤其是在资源有限的移动...

    uni-helper:使uni- *在其他编辑器(例如VSCode和WebStorm)中更好地工作

    【uni-helper】是一款专为开发者设计的工具,旨在优化基于uni-app框架的项目在非HBuilderX环境下的开发体验,特别是对于使用Visual Studio Code (VSCode) 和 WebStorm 等第三方编辑器的用户。uni-app是一个跨端的...

    allYouNeedIsASP:VB的NTOU ASP.NET课程

    学习如何将ASP.NET VB应用程序部署到IIS(Internet Information Services)服务器,以及如何使用Visual Studio进行调试,也是课程的重要组成部分。 总的来说,“allYouNeedIsASP:VB的NTOU ASP.NET课程”涵盖了VB...

    personal-web-page

    此外,开发过程中还需要对浏览器的开发者工具有所了解,它们可以帮助我们调试代码、检查元素样式和网络请求。 在"personal-web-page-main"这个文件名中,"main"通常表示这是项目的主文件或者入口点。在HTML项目中,...

    rj-app:使用Nativescript设计的RJ事件的应用程序

    开发者可以选择使用Visual Studio Code或其他支持Nativescript扩展的IDE进行编码,这些扩展将提供代码提示、调试和其他便利功能。 【文件结构解析】 从压缩包文件名“rj-app-master”来看,这是项目的主分支或者...

    bct

    6. **集成开发环境(IDE)和代码编辑器**:在使用Bootstrap和CSS时,合适的IDE或代码编辑器(如Visual Studio Code、Sublime Text、Atom等)能够提供代码补全、语法高亮、实时预览等功能,提高开发效率。 7. **...

Global site tag (gtag.js) - Google Analytics