Skip to content
This repository has been archived by the owner on Jun 5, 2019. It is now read-only.
ColinA-MSFT edited this page Jun 25, 2015 · 14 revisions

Demo

The demo is implemented for a NXP LPC1768 device, featuring 512KB of NOR FLASH and 64Kb of SRAM.

The device is enabled for the Mbed ecosystem. Any other Mbed device could be used with minimal changes to the makefile at <repo>\Zelig\LLVM2IR_results\mbed\simple\makefile.

Device setup

Build Zelig image

  • Make the FrontEnd project the startup project in your solution, or simply run the FrontEnd executable from the command line
    • If using the solution, configure the debug properties as follows:
      cfg ..\..\..\..\Zelig\CompileTime\CodeGenerator\FrontEnd\mbed_simple.FrontEndConfig

FrontEnd project debug configuration

  • If running from the command line, simply pass the same -cfg parameters pointing to the above mentioned v configuration file
  • The build output directory will be located in <repo>\Zelig\LLVM2IR_results\mbed\simple\
  • Open a command prompt, move to the root <repo> directory, and run setenv.cmd to set local environment variables.
  • Move to the build output directory <repo>\Zelig\LLVM2IR_results\mbed\simple\ and run build.bat to invoke LLVM optimizer and compiler, and finally GCC
    • GCC will link the object file created by LLVM into a simple runnable image
    • Code size of entire executable and will be dumped and disassembly will be produced
    • Build output will contain the following:
      • Microsoft.Zelig.Test.mbed.Simple.bc: the LVM binary bit code
      • Microsoft.Zelig.Test.mbed.Simple.ll: the LLVM readable bit code
      • Microsoft.Zelig.Test.mbed.Simple.TypeSystemDump.IrTxtpost: Zelig readable IR with TS details
      • Microsoft.Zelig.Test.mbed.Simple.ZeligImage: The Zelig image
      • Microsoft.Zelig.Test.mbed.Simple.ZeligIR: Zelig binary IR for reload
      • Microsoft.Zelig.Test.mbed.Simple.ZeligIR_Post: Zelig binary IR
      • Microsoft.Zelig.Test.mbed.Simple_opt.bc: LLVM optimized bit code
      • Microsoft.Zelig.Test.mbed.Simple_opt.ll: LLVM optimized readable bitcode
      • Microsoft.Zelig.Test.mbed.Simple_opt.o: LLVM object code
  • Customize and invoke deploy.bat for your Mbed device
    • (each Mbed device creates a virtual serial port on your host system, you can discover which one using Device Manager. Simply run devmgmt.msc on any Windows machine and look under the Ports node)
    • Deployment is a simple file copy through MTP, thanks to the Mbed bootloader
    • When deploying the runnable image to the device, you will see the device blink
    • Reset your device when deployment is complete (device stops blinking and copy completes)
    • Your device is now ready for attaching a debugger

Debugging

  • Launch pyOCD, which will automatically detect and connect to the device using CMSIS-DAP.
  • To debug on the command line:
    • Launch the debug.bat script.
    • Connect to the pyOCD debug server:
      target remote :3333
    • Now you can set a breakpoint with the command b_main and gdb will show you are hitting function Microsoft.Zelig.Runtime.Bootstrap::Initialization().
      gdb debug window
  • To debug in Visual Studio 2015:
    • Launch VS from the command line so that it picks up your local environment variables.
    • Open the command window (View | Other Windows | Command Window) and enter the following command:
      Debug.MIDebugLaunch /OptionsFile:<repo>\Zelig\LLVM2IR_results\mbed\simple\DebugOptions.xml /Executable:<repo>\Zelig\LLVM2IR_results\mbed\simple\LPC1768\mbed_simple.elf

A rather complete GDB tutorial can be found at http://web.mit.edu/gnu/doc/html/gdb_1.html or in this PDF file.

Welcome to Zelig!

P.S. you can install the trial version of VisualGDB to use the Visual Studio UI and debug with the usual F5/10/11 key shortcuts.

Clone this wiki locally