|
| 1 | +Ddoc |
| 2 | + |
| 3 | +$(P There are a number of commands in the Visual D menu that allow you to work with |
| 4 | +a single D source file without creating a project.) |
| 5 | + |
| 6 | +$(IMG_CENTER images/compilemenu.png) |
| 7 | + |
| 8 | +$(H2 Compile and Run) |
| 9 | + |
| 10 | +$(P This command will compile the current text window that has the edit focus. Compile options |
| 11 | +are taken from the active project configuration if the file is part of a project in the current solution. |
| 12 | +In addition options given in the $(LINK2 GlobalOptions.html, global settings) are added to the command |
| 13 | +line. Instead of building the full project, $(LINK2 http://dlang.org/rdmd.html, rdmd) is used |
| 14 | +to just add the minimal dependent modules. In order to build a runnable exectuable, you might have to add |
| 15 | +a $(D main) function to the source file or add $(D -main) to the global options. |
| 16 | +) |
| 17 | + |
| 18 | +$(P One use case for this feature is to run unittests of a single module. Compilation errors, program output |
| 19 | +and exception trace will be visible in the output window and can be double clicked to jump to the shown |
| 20 | +code locations. |
| 21 | +) |
| 22 | + |
| 23 | +$(P When used on a source file not found in any of the projects in the solution, default options |
| 24 | +from the ConsoleApp project template are used to build the executable with rdmd. This allows script |
| 25 | +like usage of D files from within the IDE, though there is currently no way to specify execution |
| 26 | +arguments. |
| 27 | +) |
| 28 | + |
| 29 | +$(H2 Compile and Debug) |
| 30 | + |
| 31 | +$(P This command is similar to "Compile and Run", but instead of running the compiled executable |
| 32 | +immediately, the debugger is started to allow further inspection. If you want to trace execution from |
| 33 | +the very beginning of the program, you should set a breakpoint at the start of $(D main) before |
| 34 | +issuing this command. |
| 35 | +) |
| 36 | + |
| 37 | +$(H2 Compile and Disassemble) |
| 38 | + |
| 39 | +$(P While optimizing code, it is often useful to take a look at the assembly generated by the |
| 40 | +compiler. This is usually done by compiling a program, starting it in a debugger until it |
| 41 | +hits an appropriate breakpoint. The disassembly view will then show the desired machine |
| 42 | +instructions. |
| 43 | +) |
| 44 | + |
| 45 | +$(P This can be a tedious and time consuming process, when all you want to look at is the |
| 46 | +disassembly of the currently written lines of code. The "Compile and Disassemble" command |
| 47 | +can take the pain out of this workflow, as it will just compile (not link) the current module |
| 48 | +with the command line options of the active project configuration and then show a |
| 49 | +disassembly dump in the Code Definition Window. It automatically synchronizes the instructions |
| 50 | +shown in the disassembly with the current caret location in the editor. |
| 51 | +) |
| 52 | + |
| 53 | +$(IMG_CENTER images/compiledisasm.png) |
| 54 | + |
| 55 | +$(P Dumping the assembly of an object file is done by an external command line tool that can |
| 56 | +be configured for each tool chain in the $(LINK2 GlobalOptions.html, global settings). |
| 57 | +For Win32, the generated object file format is rather dated OMF that is not very well |
| 58 | +supported anymore. The commercial version of the Digital Mars C++ compiler contains |
| 59 | +the command line tool $(LINK2 http://www.digitalmars.com/ctg/obj2asm.html, obj2asm), |
| 60 | +but you can also use $(LINK2 http://www.agner.org/optimize/#objconv, objconv) by Agner Fog. |
| 61 | +For any other target or compiler platform, the generated object file format is COFF, that |
| 62 | +can be disassembled with the Microsoft tool $(D dumpbin) that comes with Visual Studio. In |
| 63 | +case you use Visual D to cross compile for other architectures with LDC or GDC, you might |
| 64 | +have to run the appropriate tools from these compiler suites instead. |
| 65 | +) |
| 66 | + |
| 67 | +$(P These are working settings for the "Disassemble Command" option, but you might want to |
| 68 | +tweak these for different output, e.g. switch between AT&T and Intel style assembly. |
| 69 | +Make sure that instruction offsets are displayed so synchronization with the |
| 70 | +editor works with the help of debug line number information. |
| 71 | +) |
| 72 | + |
| 73 | +$(H3 DMD/Win32) |
| 74 | + |
| 75 | +$(PRE obj2asm -x "$(DOLLAR)(InputFile)" >"$(DOLLAR)(TargetPath)") |
| 76 | + |
| 77 | +This assumes obj2asm can be found in through PATH. If this is not the case, please add |
| 78 | +the full path to it. The same replacement macros can be used as in the project |
| 79 | +configurations. |
| 80 | + |
| 81 | +For objconv, this command is |
| 82 | + |
| 83 | +$(PRE obj2conv -fasm "$(DOLLAR)(InputFile)" "$(DOLLAR)(TargetPath)") |
| 84 | + |
| 85 | +$(H3 DMD/Win64) |
| 86 | + |
| 87 | +$(PRE "$(DOLLAR)(VCInstallDir)\bin\amd64\dumpbin" /disasm "$(DOLLAR)(InputPath)" >"$(DOLLAR)(TargetPath)" ) |
| 88 | + |
| 89 | +$(H3 DMD/Win32-COFF) |
| 90 | + |
| 91 | +dumpbin executables can be used for both architectures x86 and AMD64, no matter |
| 92 | +what architecture might be running on, so you can use the same setting as Win64, |
| 93 | +but in case you are restricted to a 32-bit OS, the respective executable can be |
| 94 | +found in the bin folder of the VC installation: |
| 95 | + |
| 96 | +$(PRE "$(DOLLAR)(VCInstallDir)\bin\dumpbin" /disasm "$(DOLLAR)(InputPath)" >"$(DOLLAR)(TargetPath)" ) |
| 97 | + |
| 98 | +There is one gotcha: dumpbin needs a DLL for doing the disassembly that is installed |
| 99 | +to $(VSInstallDir)\Common7\IDE (in VS 2013), so make sure you have this directory |
| 100 | +listed in the "Executable Paths". |
| 101 | + |
| 102 | +$(H3 LDC) |
| 103 | + |
| 104 | +dumpbin works here, too, for the x64/AMD64 architecture, but in case you want to |
| 105 | +use LLVM tools for other architectures, you'll have to change the default setting: |
| 106 | + |
| 107 | +$(PRE llvm-objdump -disassemble "$(DOLLAR)(InputPath)" >"$(DOLLAR)(TargetPath)" ) |
| 108 | + |
| 109 | +You'll have to add the path the LLVM tools to the "Executable Paths" or to the |
| 110 | +llvm-objdump command. |
| 111 | + |
| 112 | +$(H3 GDC) |
| 113 | + |
| 114 | +Similar to LDC, the alternative command is |
| 115 | + |
| 116 | +$(PRE objdump --disassemble "$(DOLLAR)(InputPath)" >"$(DOLLAR)(TargetPath)" ) |
| 117 | + |
| 118 | +Macros: |
| 119 | + TITLE=Compile Commands |
| 120 | + |
0 commit comments