1 /*===-- object.c - tool for testing libLLVM and llvm-c API ----------------===*\
3 |* The LLVM Compiler Infrastructure *|
5 |* This file is distributed under the University of Illinois Open Source *|
6 |* License. See LICENSE.TXT for details. *|
8 |*===----------------------------------------------------------------------===*|
10 |* This file implements the --object-list-sections and --object-list-symbols *|
11 |* commands in llvm-c-test. *|
13 \*===----------------------------------------------------------------------===*/
15 #include "llvm-c-test.h"
16 #include "llvm-c/Core.h"
17 #include "llvm-c/Object.h"
21 int object_list_sections(void) {
22 LLVMMemoryBufferRef MB;
24 LLVMSectionIteratorRef sect;
27 if (LLVMCreateMemoryBufferWithSTDIN(&MB, &msg)) {
28 fprintf(stderr, "Error reading file: %s\n", msg);
32 O = LLVMCreateObjectFile(MB);
34 fprintf(stderr, "Error reading object\n");
38 sect = LLVMGetSections(O);
39 while (!LLVMIsSectionIteratorAtEnd(O, sect)) {
40 printf("'%s': @0x%08" PRIx64 " +%" PRIu64 "\n", LLVMGetSectionName(sect),
41 LLVMGetSectionAddress(sect), LLVMGetSectionSize(sect));
43 LLVMMoveToNextSection(sect);
46 LLVMDisposeSectionIterator(sect);
48 LLVMDisposeObjectFile(O);
53 int object_list_symbols(void) {
54 LLVMMemoryBufferRef MB;
56 LLVMSectionIteratorRef sect;
57 LLVMSymbolIteratorRef sym;
60 if (LLVMCreateMemoryBufferWithSTDIN(&MB, &msg)) {
61 fprintf(stderr, "Error reading file: %s\n", msg);
65 O = LLVMCreateObjectFile(MB);
67 fprintf(stderr, "Error reading object\n");
71 sect = LLVMGetSections(O);
72 sym = LLVMGetSymbols(O);
73 while (!LLVMIsSymbolIteratorAtEnd(O, sym)) {
75 LLVMMoveToContainingSection(sect, sym);
76 printf("%s @0x%08" PRIx64 " +%" PRIu64 " (%s)\n", LLVMGetSymbolName(sym),
77 LLVMGetSymbolAddress(sym), LLVMGetSymbolSize(sym),
78 LLVMGetSectionName(sect));
80 LLVMMoveToNextSymbol(sym);
83 LLVMDisposeSymbolIterator(sym);
85 LLVMDisposeObjectFile(O);