├── .gitignore ├── AUTHORS ├── CMakeLists.txt ├── COPYING ├── COPYING-LGPLV3 ├── NEWS ├── README ├── TODO ├── VERSION.cmake ├── cmake └── modules │ ├── FindDWARF.cmake │ └── FindSphinx.cmake ├── doc ├── CMakeLists.txt ├── cli.rst ├── conf.py.in ├── examples.rst ├── fulltoc.rst ├── index.rst ├── locstat.zw ├── syntax.rst ├── tutorial.rst ├── zw_vocabulary_core-blurb.txt └── zw_vocabulary_dwarf-blurb.txt ├── dwgrep ├── CMakeLists.txt ├── dwgrep.cc ├── genman.cc ├── options.cc └── options.hh ├── extern └── optional.hpp ├── known-dwarf.awk ├── known-elf.awk ├── libzwerg ├── CMakeLists.txt ├── atval.cc ├── atval.hh ├── bindings.cc ├── bindings.hh ├── build-version-script.sh ├── build.cc ├── builtin-aset.cc ├── builtin-aset.hh ├── builtin-closure.cc ├── builtin-closure.hh ├── builtin-cmp.cc ├── builtin-cmp.hh ├── builtin-cst.cc ├── builtin-cst.hh ├── builtin-dw-abbrev.cc ├── builtin-dw-abbrev.hh ├── builtin-dw-voc.cc ├── builtin-dw.cc ├── builtin-dw.hh ├── builtin-shf.cc ├── builtin-shf.hh ├── builtin-symbol.cc ├── builtin-symbol.hh ├── builtin.cc ├── builtin.hh ├── cache.cc ├── cache.hh ├── constant.cc ├── constant.hh ├── coverage.cc ├── coverage.hh ├── docstring.cc ├── docstring.hh ├── dwcst.cc ├── dwcst.hh ├── dwfl_context.cc ├── dwfl_context.hh ├── dwgrep-gendoc.cc ├── dwit.cc ├── dwit.hh ├── dwmods.cc ├── dwmods.hh ├── dwpp.hh ├── flag_saver.hh ├── init.cc ├── init.hh ├── int.cc ├── int.hh ├── known-dwarf-macro-gnu.h ├── layout.cc ├── layout.hh ├── lexer.ll ├── libzwerg-dw.cc ├── libzwerg-dw.h ├── libzwerg.cc ├── libzwerg.h ├── libzwerg.hh ├── libzwerg.map ├── libzwergP.hh ├── op.cc ├── op.hh ├── overload.cc ├── overload.hh ├── parser.yy ├── pred_result.cc ├── pred_result.hh ├── scon.cc ├── scon.hh ├── selector.cc ├── selector.hh ├── stack.cc ├── stack.hh ├── strip.cc ├── strip.hh ├── test-builtin-cmp.cc ├── test-coverage.cc ├── test-dw.cc ├── test-int.cc ├── test-op.cc ├── test-parser.cc ├── test-stub.cc ├── test-value-cst.cc ├── test-zw-aux.cc ├── test-zw-aux.hh ├── tree.cc ├── tree.hh ├── tree_cr.cc ├── tree_cr.hh ├── value-aset.cc ├── value-aset.hh ├── value-closure.cc ├── value-closure.hh ├── value-cst.cc ├── value-cst.hh ├── value-dw.cc ├── value-dw.hh ├── value-seq.cc ├── value-seq.hh ├── value-str.cc ├── value-str.hh ├── value-symbol.cc ├── value-symbol.hh ├── value.cc └── value.hh ├── tests ├── CMakeLists.txt ├── a-common.out ├── a1.out ├── aranges.c ├── aranges.o ├── attribute-die-cooked-no-dup.o ├── attribute-die-cooked-no-dup.tcl ├── bitcount.c ├── bitcount.o ├── char_16_32.cc ├── char_16_32.o ├── const_value_block.cc ├── const_value_block.o ├── const_value_on_enum_with_type.cc ├── const_value_on_enum_with_type.o ├── const_value_signedness_from_enumerator.cc ├── const_value_signedness_from_enumerator.o ├── const_value_signedness_small_enough.o ├── const_value_signedness_small_enough.tcl ├── defaulted.cc ├── defaulted.o ├── duplicate-const ├── dwarf.exp ├── dwz-dupfile ├── dwz-dupfile.c ├── dwz-partial ├── dwz-partial.c ├── dwz-partial2-1 ├── dwz-partial2-C ├── dwz-partial2.c ├── dwz-partial3-1 ├── dwz-partial3-C ├── dwz-partial3.c ├── dwz-partial4-1.o ├── dwz-partial4-C ├── dwz-partial4.tcl ├── empty ├── empty.s ├── entry_dwarf_counts_every_unit_anew.o ├── entry_dwarf_counts_every_unit_anew.tcl ├── enum.cc ├── enum.o ├── float_const_value.cc ├── float_const_value.o ├── float_const_value.o-armv7hl ├── float_const_value.o-ppc64 ├── haschildren_childless ├── haschildren_childless.s ├── imported-AT_decl_file.o ├── imported-AT_decl_file.tcl ├── inconsistent-types ├── inconsistent-types.cc ├── nontrivial-types.c ├── nontrivial-types.o ├── nullptr.cc ├── nullptr.o ├── pointer_const_value.c ├── pointer_const_value.o ├── ptrmember_const_value.o ├── ptrmember_const_value.s ├── testfile_const_type ├── testfile_const_type.c ├── tests.sh ├── twocus ├── twocus1.c ├── twocus2.c ├── typedef.c ├── typedef.o ├── y-mips.o └── y.o └── version.h.in /.gitignore: -------------------------------------------------------------------------------- 1 | version.h 2 | CMakeCache.txt 3 | CMakeFiles/ 4 | CTestTestfile.cmake 5 | Makefile 6 | build/ 7 | cmake_install.cmake 8 | install_manifest.txt 9 | doc/CMakeFiles/ 10 | doc/_build/ 11 | doc/_doctrees/ 12 | doc/_source/ 13 | doc/html/ 14 | dwgrep 15 | dwgrep-gendoc 16 | known-dwarf.h 17 | lexer.cc 18 | lexer.hh 19 | libzwerg.so 20 | libzwerg.so.0.1 21 | libzwerg/CMakeFiles/ 22 | parser.cc 23 | parser.hh 24 | test-int 25 | test-parser 26 | tests/CMakeFiles/ 27 | tmp/ 28 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # This file lists the people who contributed to making of dwgrep in 2 | # alphabetical order. 3 | 4 | Jonathan Wakely 5 | Jakub Filak 6 | Josh Stone 7 | Petr Machata 8 | Scott Tsai 9 | Simon Marchi 10 | Tom Tromey 11 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED (VERSION 2.8.8) 2 | PROJECT (dwgrep C CXX) 3 | 4 | CMAKE_POLICY(SET CMP0075 NEW) 5 | 6 | INCLUDE (${CMAKE_SOURCE_DIR}/VERSION.cmake) 7 | SET (VERSION ${DWGREP_MAJOR}.${DWGREP_MINOR}) 8 | 9 | CONFIGURE_FILE ("${CMAKE_CURRENT_SOURCE_DIR}/version.h.in" 10 | "${CMAKE_CURRENT_BINARY_DIR}/version.h" 11 | @ONLY) 12 | 13 | INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/libzwerg) 14 | INCLUDE_DIRECTORIES (${CMAKE_BINARY_DIR}) 15 | 16 | SET (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) 17 | 18 | INCLUDE (CheckCXXCompilerFlag) 19 | CHECK_CXX_COMPILER_FLAG ("-std=c++14" COMPILER_SUPPORTS_CXX14) 20 | IF (COMPILER_SUPPORTS_CXX14) 21 | SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") 22 | ELSE () 23 | MESSAGE (FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support.") 24 | ENDIF () 25 | 26 | SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wnon-virtual-dtor -O2 -g") 27 | 28 | FIND_PACKAGE (DWARF REQUIRED) 29 | FIND_PACKAGE (FLEX REQUIRED) 30 | FIND_PACKAGE (BISON REQUIRED) 31 | 32 | FIND_PACKAGE (GTest) 33 | IF (GTEST_FOUND) 34 | INCLUDE_DIRECTORIES (${GTEST_INCLUDE_DIRS}) 35 | ENDIF () 36 | 37 | FIND_PACKAGE (Sphinx) 38 | IF (SPHINX_EXECUTABLE) 39 | ADD_SUBDIRECTORY (doc) 40 | ELSE () 41 | MESSAGE (STATUS "Sphinx not found, documentation will NOT be built.") 42 | ENDIF () 43 | 44 | ENABLE_TESTING () 45 | 46 | SET (ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${VERSION}) 47 | ADD_CUSTOM_TARGET (dist 48 | COMMAND git archive --prefix=${ARCHIVE_NAME}/ HEAD 49 | | bzip2 > ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.bz2 50 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) 51 | 52 | ADD_SUBDIRECTORY (libzwerg) 53 | ADD_SUBDIRECTORY (dwgrep) 54 | ADD_SUBDIRECTORY (tests) 55 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | -*-org-*- 2 | * version 0.4 [2018-04-07 Sat] 3 | 4 | ** Changes in dwgrep 5 | 6 | - Fix file name shown when -H is passed and no files are given on the command 7 | line. Before, it was somewhere and empty string elsewhere. Now it's 8 | everywhere. 9 | 10 | - Support passing arguments to scripts from the command line. Two new command 11 | line flags are available: -a for passing in simple strings, and --a, whose 12 | argument is parsed as Zwerg expression, and TOS of the yielded stack is passed 13 | to the script. The arguments are pushed to input stack of the query 14 | expression, which can bind them using lexical scope, or use arbitrarily. 15 | - Fixes #13: Support passing arguments to scripts from command line 16 | 17 | For example: 18 | $ ./dwgrep/dwgrep foo --a DW_AT_language \ 19 | -e '(|At| entry attribute (label == At))' 20 | language C99 21 | 22 | - Position reported at Dwarf values passed in from command line used to be 23 | always 0. Now it's the file's position on command line: 24 | 25 | $ dwgrep /bin/true /bin/false -he '[|Dw| Dw name, Dw pos]' 26 | ["/bin/true", 0] 27 | ["/bin/false", 1] 28 | 29 | ** Changes in libzwerg 30 | 31 | - Fix a bug introduced in 0.3 where a captured expression wasn't reset properly, 32 | due to which after the first list was produced, the following lists were all 33 | empty. 34 | 35 | ** Changes in Dwarf support 36 | 37 | - Support DW_DEFAULTED_* suite of constants. Use them to decode DW_AT_defaulted. 38 | 39 | - Support decoding of DWARF 5 attributes DW_AT_string_length_bit_size, 40 | DW_AT_string_length_byte_size, DW_AT_rank, DW_AT_alignment, 41 | DW_AT_str_offsets_base, DW_AT_addr_base, DW_AT_rnglists_base, and 42 | DW_AT_loclists_base. 43 | 44 | - Unhandled attributes in the DW_AT_lo_user .. DW_AT_hi_user area are now 45 | decoded implicitly as unsigned. 46 | 47 | - Integral attributes with encoding DW_ATE_boolean are now decoded as booleans, 48 | not as plain unsigned numbers. 49 | 50 | - Attributes with block forms whose length is 1, 2, 4 or 8 bytes, are decoded as 51 | if they were integrals. Encoding of the attribute determines how exactly will 52 | the integral be decoded. 53 | 54 | ** Changes in Zwerg language 55 | 56 | - Allow bindings named the same way as a built-in word. This is important for 57 | forward-compatibility: adding built-in words doesn't break existing queries 58 | that use that name for a binding. 59 | - Fixes #29: Allow naming variables like builtins 60 | 61 | * version 0.3 [2017-12-09 Sat] 62 | 63 | ** Backward-incompatible Changes 64 | 65 | - Change parsing of integer literals. Integer literals are now seqences of 66 | alphanumeric characters that start with a decimal digit (e.g. 123, 0xff), 67 | whereas before, they were seqences of characters indicated by the number 68 | prefix (e.g. 0x indicated [0-9a-f] as appropriate character set). 69 | 70 | Thus apparent typos such as "0b123" are not parsed as "0b1" followed by "23" 71 | anymore, but as "0b123", which is flagged as error. Likewise strings such as 72 | "123drop", which were previously valid, are not anymore. 73 | 74 | ** Other Changes 75 | 76 | - dwgrep can now dump location lists. 77 | 78 | - Small changes to the C API and a lot of documentation. The API in still 79 | unstable and preliminary. 80 | 81 | - Fix building on GCC 4.8 and 7.0. 82 | - Fixes #28: Include header for std::function 83 | 84 | - Rework how variable binding works. There should be no user-visible changes 85 | for programs that were not relying on undocumented behavior. 86 | - Fixes #25: Frame cloning too expensive 87 | 88 | - Error messages are now printed to stderr, not stdout. 89 | 90 | - Fix --help to include full first sentence of option description, and not 91 | stop at the first period. 92 | 93 | 94 | * version 0.2 [2015-02-28 Sat] 95 | 96 | - ELF symbol tables are supported. New word `symbol` applicable to 97 | DWARF value yields ELF symbols. Words `label`, `value`, 98 | `address`, `name`, `size` `binding`, `visibility` operate on ELF 99 | symbols. 100 | 101 | - C API is considerably more complete, and now used exclusively by 102 | the "dwgrep" command-line driver to communicate with libzwerg. It 103 | is however still not considered stable and is undocumented. 104 | 105 | - The word `length` is now applicable to location lists. 106 | 107 | - Bug fixes (issues #5, #6, #7, #8, #14, #15, #16, #17, #22, #26). 108 | 109 | 110 | * version 0.1 [2014-12-10 Sun] 111 | 112 | - Initial release. 113 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | dwgrep is a tool for querying Dwarf (debuginfo) graphs. Queries are 2 | written in a language called Zwerg, the syntax of which is described 3 | in doc/syntax.rst. The engine itself is available as a shared library 4 | which can be used from C. 5 | 6 | Full documentation is available in the doc/ sub-directory. In particular, 7 | check out . An HTML rendition of the full documentation is 8 | published at . 9 | -------------------------------------------------------------------------------- /VERSION.cmake: -------------------------------------------------------------------------------- 1 | SET(DWGREP_MAJOR "0") 2 | SET(DWGREP_MINOR "4") 3 | -------------------------------------------------------------------------------- /cmake/modules/FindDWARF.cmake: -------------------------------------------------------------------------------- 1 | # - Find Dwarf 2 | # Find the dwarf.h header from elf utils 3 | # 4 | # DWARF_INCLUDE_DIR - where to find dwarf.h, etc. 5 | # DWARF_LIBRARIES - List of libraries when using elf utils. 6 | # DWARF_FOUND - True if fdo found. 7 | 8 | message(STATUS "Checking availability of DWARF and ELF development libraries") 9 | 10 | INCLUDE(CheckLibraryExists) 11 | 12 | if (DWARF_INCLUDE_DIR AND ELF_INCLUDE_DIR 13 | AND LIBDW_INCLUDE_DIR AND DWARF_LIBRARY AND ELF_LIBRARY) 14 | # Already in cache, be silent 15 | set(DWARF_FIND_QUIETLY TRUE) 16 | endif (DWARF_INCLUDE_DIR AND ELF_INCLUDE_DIR 17 | AND LIBDW_INCLUDE_DIR AND DWARF_LIBRARY AND ELF_LIBRARY) 18 | 19 | if (DEFINED LIBDW_PATH) 20 | set (USER_LIBDW_INCLUDE_PATH ${LIBDW_PATH}/include) 21 | set (USER_LIBDW_LIB_PATH ${LIBDW_PATH}) 22 | else () 23 | set (USER_LIBDW_INCLUDE_PATH "") 24 | set (USER_LIBDW_LIB_PATH "") 25 | endif () 26 | 27 | if (DEFINED LIBELF_PATH) 28 | set (USER_LIBELF_INCLUDE_PATH ${LIBELF_PATH}/include) 29 | set (USER_LIBELF_LIB_PATH ${LIBELF_PATH}) 30 | else () 31 | set (USER_LIBELF_INCLUDE_PATH "") 32 | set (USER_LIBELF_LIB_PATH "") 33 | endif () 34 | 35 | find_path(DWARF_INCLUDE_DIR dwarf.h 36 | HINTS ${USER_LIBDW_INCLUDE_PATH} 37 | ) 38 | 39 | find_path(ELF_INCLUDE_DIR elf.h 40 | HINTS ${USER_LIBELF_INCLUDE_PATH} 41 | ) 42 | 43 | find_path(LIBDW_INCLUDE_DIR elfutils/libdw.h 44 | HINTS ${USER_LIBDW_INCLUDE_PATH} 45 | ) 46 | 47 | find_library(DWARF_LIBRARY 48 | NAMES dw 49 | HINTS ${USER_LIBDW_LIB_PATH} 50 | PATH_SUFFIXES lib lib64 51 | ) 52 | 53 | find_library(ELF_LIBRARY 54 | NAMES elf 55 | HINTS ${USER_LIBELF_LIB_PATH} 56 | PATH_SUFFIXES lib lib64 57 | ) 58 | 59 | if (DWARF_INCLUDE_DIR AND ELF_INCLUDE_DIR 60 | AND LIBDW_INCLUDE_DIR AND DWARF_LIBRARY AND ELF_LIBRARY) 61 | set(DWARF_FOUND TRUE) 62 | set(DWARF_LIBRARIES ${DWARF_LIBRARY} ${ELF_LIBRARY}) 63 | 64 | set(CMAKE_REQUIRED_LIBRARIES ${DWARF_LIBRARIES}) 65 | # check if libdw have the dwfl_module_build_id routine, 66 | # i.e. if it supports the buildid mechanism to match binaries 67 | # to detached debug info sections (the -debuginfo packages in 68 | # distributions such as fedora). We do it against libelf 69 | # because, IIRC, some distros include libdw linked statically 70 | # into libelf. 71 | check_library_exists(elf dwfl_module_build_id "" HAVE_DWFL_MODULE_BUILD_ID) 72 | else (DWARF_INCLUDE_DIR AND ELF_INCLUDE_DIR 73 | AND LIBDW_INCLUDE_DIR AND DWARF_LIBRARY AND ELF_LIBRARY) 74 | set(DWARF_FOUND FALSE) 75 | set(DWARF_LIBRARIES) 76 | endif (DWARF_INCLUDE_DIR AND ELF_INCLUDE_DIR 77 | AND LIBDW_INCLUDE_DIR AND DWARF_LIBRARY AND ELF_LIBRARY) 78 | 79 | if (DWARF_FOUND) 80 | if (NOT DWARF_FIND_QUIETLY) 81 | message(STATUS "Found dwarf.h header: ${DWARF_INCLUDE_DIR}") 82 | message(STATUS "Found elf.h header: ${ELF_INCLUDE_DIR}") 83 | message(STATUS "Found elfutils/libdw.h header: ${LIBDW_INCLUDE_DIR}") 84 | message(STATUS "Found libdw library: ${DWARF_LIBRARY}") 85 | message(STATUS "Found libelf library: ${ELF_LIBRARY}") 86 | endif (NOT DWARF_FIND_QUIETLY) 87 | else (DWARF_FOUND) 88 | if (DWARF_FIND_REQUIRED) 89 | # Check if we are in a Red Hat (RHEL) or Fedora system to tell 90 | # exactly which packages should be installed. Please send 91 | # patches for other distributions. 92 | find_path(FEDORA fedora-release /etc) 93 | find_path(REDHAT redhat-release /etc) 94 | if (FEDORA OR REDHAT) 95 | if (NOT DWARF_INCLUDE_DIR OR NOT ELF_INCLUDE_DIR 96 | OR NOT LIBDW_INCLUDE_DIR) 97 | message(STATUS "Please install the elfutils-devel package") 98 | endif (NOT DWARF_INCLUDE_DIR OR NOT ELF_INCLUDE_DIR 99 | OR NOT LIBDW_INCLUDE_DIR) 100 | if (NOT DWARF_LIBRARY) 101 | message(STATUS "Please install the elfutils-libs package") 102 | endif (NOT DWARF_LIBRARY) 103 | if (NOT ELF_LIBRARY) 104 | message(STATUS "Please install the elfutils-libelf package") 105 | endif (NOT ELF_LIBRARY) 106 | else (FEDORA OR REDHAT) 107 | if (NOT DWARF_INCLUDE_DIR) 108 | message(STATUS "Could NOT find dwarf include dir") 109 | endif (NOT DWARF_INCLUDE_DIR) 110 | if (NOT ELF_INCLUDE_DIR) 111 | message(STATUS "Could NOT find elf include dir") 112 | endif (NOT ELF_INCLUDE_DIR) 113 | if (NOT LIBDW_INCLUDE_DIR) 114 | message(STATUS "Could NOT find libdw include dir") 115 | endif (NOT LIBDW_INCLUDE_DIR) 116 | if (NOT DWARF_LIBRARY) 117 | message(STATUS "Could NOT find libdw library") 118 | endif (NOT DWARF_LIBRARY) 119 | if (NOT ELF_LIBRARY) 120 | message(STATUS "Could NOT find libelf library") 121 | endif (NOT ELF_LIBRARY) 122 | endif (FEDORA OR REDHAT) 123 | message(FATAL_ERROR "Could NOT find some ELF and DWARF libraries, please install the missing packages") 124 | endif (DWARF_FIND_REQUIRED) 125 | endif (DWARF_FOUND) 126 | 127 | mark_as_advanced(DWARF_INCLUDE_DIR ELF_INCLUDE_DIR 128 | LIBDW_INCLUDE_DIR DWARF_LIBRARY ELF_LIBRARY) 129 | include_directories(${DWARF_INCLUDE_DIR} ${LIBDW_INCLUDE_DIR} ${ELF_INCLUDE_DIR}) 130 | 131 | message(STATUS "Checking availability of DWARF and ELF development libraries - done") 132 | -------------------------------------------------------------------------------- /cmake/modules/FindSphinx.cmake: -------------------------------------------------------------------------------- 1 | find_program(SPHINX_EXECUTABLE NAMES sphinx-build 2 | HINTS 3 | $ENV{SPHINX_DIR} 4 | PATH_SUFFIXES bin 5 | DOC "Sphinx documentation generator" 6 | ) 7 | 8 | include(FindPackageHandleStandardArgs) 9 | 10 | find_package_handle_standard_args(Sphinx DEFAULT_MSG 11 | SPHINX_EXECUTABLE 12 | ) 13 | 14 | mark_as_advanced(SPHINX_EXECUTABLE) 15 | -------------------------------------------------------------------------------- /doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SET (DocSources 2 | 3 | cli.rst 4 | fulltoc.rst 5 | index.rst 6 | syntax.rst 7 | tutorial.rst 8 | examples.rst 9 | zw_vocabulary_core-blurb.txt 10 | zw_vocabulary_dwarf-blurb.txt 11 | ) 12 | 13 | IF (NOT DEFINED SPHINX_THEME) 14 | SET (SPHINX_THEME default) 15 | ENDIF () 16 | 17 | IF (NOT DEFINED SPHINX_THEME_DIR) 18 | SET (SPHINX_THEME_DIR) 19 | ENDIF () 20 | 21 | SET (AUX_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_source") 22 | SET (BINARY_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/_build") 23 | SET (SPHINX_CACHE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_doctrees") 24 | SET (SPHINX_HTML_DIR "${CMAKE_CURRENT_BINARY_DIR}/html") 25 | SET (SPHINX_MAN_DIR "${CMAKE_CURRENT_BINARY_DIR}/man") 26 | 27 | FOREACH (SOURCE ${DocSources}) 28 | CONFIGURE_FILE ("${SOURCE}" "${AUX_SOURCE_DIR}/${SOURCE}" COPYONLY) 29 | ENDFOREACH () 30 | 31 | CONFIGURE_FILE ("${CMAKE_CURRENT_SOURCE_DIR}/conf.py.in" 32 | "${BINARY_BUILD_DIR}/conf.py" 33 | @ONLY) 34 | 35 | ADD_CUSTOM_TARGET (GenerateDocs 36 | COMMAND ../libzwerg/dwgrep-gendoc 37 | zw_vocabulary_core "Core vocabulary" 38 | > "${AUX_SOURCE_DIR}/vocabulary-core.rst" 39 | 40 | COMMAND ../libzwerg/dwgrep-gendoc 41 | zw_vocabulary_dwarf "Dwarf vocabulary" 42 | > "${AUX_SOURCE_DIR}/vocabulary-dwarf.rst" 43 | 44 | DEPENDS ../libzwerg/dwgrep-gendoc 45 | COMMENT "Building vocabulary reference") 46 | 47 | ADD_CUSTOM_TARGET (GenerateOptions 48 | COMMAND ../dwgrep/dwgrep-genman 49 | > "${AUX_SOURCE_DIR}/options.txt" 50 | 51 | DEPENDS ../dwgrep/dwgrep-genman 52 | COMMENT "Building CLI option reference") 53 | 54 | ADD_CUSTOM_TARGET (doc-html 55 | ${SPHINX_EXECUTABLE} -q -b html -c "${BINARY_BUILD_DIR}" 56 | -d "${SPHINX_CACHE_DIR}" "${AUX_SOURCE_DIR}" "${SPHINX_HTML_DIR}" 57 | COMMENT "Building HTML documentation") 58 | 59 | ADD_CUSTOM_TARGET (doc-man 60 | ${SPHINX_EXECUTABLE} -q -b man -c "${BINARY_BUILD_DIR}" 61 | -d "${SPHINX_CACHE_DIR}" "${AUX_SOURCE_DIR}" "${SPHINX_MAN_DIR}" 62 | COMMENT "Building manual pages") 63 | 64 | INSTALL (FILES ${SPHINX_MAN_DIR}/dwgrep.1 65 | DESTINATION share/man/man1 OPTIONAL) 66 | 67 | ADD_CUSTOM_TARGET (doc) 68 | ADD_DEPENDENCIES (doc doc-html doc-man) 69 | 70 | ADD_CUSTOM_TARGET (doc-gen) 71 | ADD_DEPENDENCIES (doc-gen GenerateDocs GenerateOptions) 72 | 73 | ADD_DEPENDENCIES (doc-html doc-gen) 74 | ADD_DEPENDENCIES (doc-man doc-gen) 75 | -------------------------------------------------------------------------------- /doc/cli.rst: -------------------------------------------------------------------------------- 1 | .. _cli: 2 | 3 | Command line reference 4 | ====================== 5 | 6 | Synopsis 7 | -------- 8 | 9 | :: 10 | 11 | dwgrep [OPTIONS] PATTERN [FILE...] 12 | dwgrep [OPTIONS] [-e PATTERN | -f FILE] [FILE...] 13 | 14 | Description 15 | ----------- 16 | 17 | Dwgrep is a tool for querying Dwarf (debuginfo) graphs. Queries are 18 | written in a language called Zwerg, the syntax of which is described 19 | on project web pages (see below). The engine itself is available as a 20 | shared library which can be used from C. 21 | 22 | Options 23 | ------- 24 | 25 | .. include:: options.txt 26 | 27 | Examples 28 | -------- 29 | 30 | Find ELF files:: 31 | 32 | $ dwgrep -sh $(find /usr/lib64/ -type f) -e 'name' 33 | /usr/lib64/libogrove.so.0.0.1 34 | /usr/lib64/libmp3lame.so.0.0.0 35 | /usr/lib64/libgimpcolor-2.0.so.0.600.12 36 | /usr/lib64/libmx-gtk-1.0.so.0.0.0 37 | /usr/lib64/libkpimidentities.so.4.6.0 38 | [... etc ...] 39 | 40 | Find ELF files that include Dwarf information:: 41 | 42 | $ dwgrep -sh $(find /usr/lib64/ -type f) -e '?(unit) name' 43 | /usr/lib64/python3.2/config-3.2mu/python.o 44 | /usr/lib64/libxqilla.so.5.0.4 45 | [... etc ...] 46 | 47 | Find namespace names defined in one of them:: 48 | 49 | $ dwgrep /usr/lib64/libxqilla.so.5.0.4 -e ' 50 | entry ?TAG_namespace name' | sort -u 51 | __debug 52 | __detail 53 | __gnu_cxx 54 | __gnu_debug 55 | std 56 | xercesc_3_0 57 | XQParser 58 | 59 | Find names of variables defined in the namespace ``xercesc_3_0``:: 60 | 61 | $ dwgrep /usr/lib64/libxqilla.so.5.0.4 -e ' 62 | entry ?TAG_namespace (name == "xercesc_3_0") 63 | child ?TAG_variable name' | sort -u 64 | chAmpersand 65 | chAsterisk 66 | chAt 67 | chBackSlash 68 | chBang 69 | [... etc ...] 70 | 71 | Of those, only list the ones that don't start in ``ch``:: 72 | 73 | $ dwgrep /usr/lib64/libxqilla.so.5.0.4 -e ' 74 | entry ?TAG_namespace (name == "xercesc_3_0") 75 | child ?TAG_variable name 76 | (!~ "ch.*")' | sort -u 77 | gControlCharMask 78 | gDefOutOfMemoryErrMsg 79 | gFirstNameCharMask 80 | gNameCharMask 81 | 82 | Look where they are declared:: 83 | 84 | $ dwgrep /usr/lib64/libxqilla.so.5.0.4 -e ' 85 | entry ?TAG_namespace (name == "xercesc_3_0") 86 | child ?TAG_variable (name !~ "ch.*") 87 | @AT_decl_file' | sort -u 88 | /usr/include/xercesc/util/OutOfMemoryException.hpp 89 | /usr/include/xercesc/util/XMLChar.hpp 90 | 91 | Use formatting strings to include line number information in the mix:: 92 | 93 | $ dwgrep /usr/lib64/libxqilla.so.5.0.4 -e ' 94 | entry ?TAG_namespace (name == "xercesc_3_0") 95 | child ?TAG_variable (name !~ "ch.*") 96 | "%(@AT_decl_file%): %(dup @AT_decl_line%)"' | sort -u 97 | /usr/include/xercesc/util/OutOfMemoryException.hpp: 32 98 | /usr/include/xercesc/util/XMLChar.hpp: 33 99 | /usr/include/xercesc/util/XMLChar.hpp: 34 100 | /usr/include/xercesc/util/XMLChar.hpp: 35 101 | [... etc ...] 102 | 103 | More examples are available in documentation on syntax and in the 104 | tutorial. 105 | 106 | See also 107 | -------- 108 | 109 | To learn more about Dwarf, check out: 110 | 111 | - Introduction to the DWARF Debugging Format 112 | 113 | - Dwarf standard 114 | - Project homepage 115 | -------------------------------------------------------------------------------- /doc/examples.rst: -------------------------------------------------------------------------------- 1 | Assorted examples 2 | ================= 3 | 4 | Type mismatch in ``DW_AT_specification`` 5 | ---------------------------------------- 6 | 7 | Find type DIE's that are inconsistent between instance and 8 | specification. This is `GCC bug 43053`__:: 9 | 10 | let A := entry ?TAG_subprogram; 11 | let B := A child ?TAG_formal_parameter; 12 | let C := A @AT_specification child ?TAG_formal_parameter; 13 | (B pos == C pos) (B @AT_type != C @AT_type) 14 | 15 | *A* holds the offending subprogram, and *B* and *C* are the two 16 | mismatched types. 17 | 18 | .. __: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43053 19 | 20 | 21 | Duplicate ``DW_AT_const_type`` 22 | ------------------------------ 23 | 24 | Find two distinct cv-modifier DIE's that both qualify the same 25 | underlying type the same way. This is `GCC bug 56740`__:: 26 | 27 | let A := entry (?TAG_const_type || ?TAG_volatile_type || ?TAG_restrict_type); 28 | let B := A root child* (> A) (label == A label) (@AT_type == A @AT_type); 29 | 30 | *A* and *B* are the two duplicate DIE's. 31 | 32 | .. __: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56740 33 | -------------------------------------------------------------------------------- /doc/fulltoc.rst: -------------------------------------------------------------------------------- 1 | .. _fulltoc: 2 | 3 | Table of contents 4 | ================= 5 | 6 | .. toctree:: 7 | :maxdepth: 3 8 | 9 | cli 10 | tutorial 11 | examples 12 | syntax 13 | vocabulary-core 14 | vocabulary-dwarf 15 | -------------------------------------------------------------------------------- /doc/locstat.zw: -------------------------------------------------------------------------------- 1 | let seq := {|B| (1 add (< B))*}; 2 | 3 | [ 4 | entry 5 | 6 | if ?DW_TAG_formal_parameter then ( 7 | // Of formal parameters we ignore those that are children of 8 | // subprograms that are themselves declarations. 9 | ?(parent !DW_TAG_subroutine_type !(@DW_AT_declaration == true)) 10 | ) else ( 11 | ?DW_TAG_variable 12 | ) 13 | 14 | // Ignore those that are just declarations or artificial. 15 | !(@DW_AT_declaration == true) 16 | !(@DW_AT_artificial == true) 17 | 18 | // let bool := {|Pred| ?(Pred) true || false}; 19 | // let has_loc := {@DW_AT_location} bool 20 | let has_loc := (?(@DW_AT_location) true || false); 21 | 22 | // Also ignore extern globals -- these have DW_AT_external and no 23 | // DW_AT_location. 24 | !((@DW_AT_external == true) (has_loc == true)) 25 | 26 | let ranges := [(!(address) parent)* address]; 27 | 28 | let coverage := 29 | if ?DW_AT_const_value then 100 30 | else if (has_loc == false) then 0 31 | else ( 32 | let sum := {0 (over elem (pos == 0) add 33 | swap [|A| A elem (pos != 0)] swap)* 34 | swap (== []) drop}; 35 | 36 | let ranges := [(!(address) parent)* address]; 37 | let loc := [@AT_location ?(elem) address]; 38 | [let rr := ranges elem; 39 | let ll := loc elem ?(rr ?overlaps); 40 | let cov_high := rr high ll high swap? ?gt; 41 | let cov_low := rr low ll low swap? ?lt; 42 | cov_high cov_low sub] sum 100 mul 43 | [let e := ranges elem; e high e low sub] sum 44 | if (== 0) then 0 else (div dec) 45 | ); 46 | 47 | coverage 48 | ] 49 | 50 | # Frequency table. Shows number of occurences of each coverage 51 | # percentage. 52 | [|A| 0 101 seq [A elem (== swap)] length] 53 | -------------------------------------------------------------------------------- /doc/zw_vocabulary_core-blurb.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/doc/zw_vocabulary_core-blurb.txt -------------------------------------------------------------------------------- /doc/zw_vocabulary_dwarf-blurb.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/doc/zw_vocabulary_dwarf-blurb.txt -------------------------------------------------------------------------------- /dwgrep/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_LIBRARY (AuxLib OBJECT 2 | ../libzwerg/strip.cc 3 | options.cc) 4 | 5 | ADD_EXECUTABLE (dwgrep dwgrep.cc $) 6 | ADD_EXECUTABLE (dwgrep-genman genman.cc $) 7 | INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}) 8 | TARGET_LINK_LIBRARIES (dwgrep libzwerg) 9 | 10 | INSTALL (TARGETS dwgrep RUNTIME DESTINATION bin) 11 | -------------------------------------------------------------------------------- /dwgrep/genman.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #include 30 | #include "options.hh" 31 | #include "libzwerg/strip.hh" 32 | 33 | int 34 | main(int argc, char *argv[]) 35 | { 36 | std::map , std::string>> opts 37 | = merge_options (ext_options); 38 | 39 | for (auto const &opt: opts) 40 | { 41 | bool seen = false; 42 | for (auto const &l: opt.second.first) 43 | { 44 | std::cout << (seen ? ", ``" : "``") << l << "``"; 45 | seen = true; 46 | } 47 | 48 | std::string ds = strip (opt.second.second, "\n"); 49 | std::cout << "\n" << ds << "\n\n"; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /dwgrep/options.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | Copyright (C) 2014 Red Hat, Inc. 4 | This file is part of dwgrep. 5 | 6 | This file is free software; you can redistribute it and/or modify 7 | it under the terms of either 8 | 9 | * the GNU Lesser General Public License as published by the Free 10 | Software Foundation; either version 3 of the License, or (at 11 | your option) any later version 12 | 13 | or 14 | 15 | * the GNU General Public License as published by the Free 16 | Software Foundation; either version 2 of the License, or (at 17 | your option) any later version 18 | 19 | or both in parallel, as here. 20 | 21 | dwgrep is distributed in the hope that it will be useful, but 22 | WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | General Public License for more details. 25 | 26 | You should have received copies of the GNU General Public License and 27 | the GNU Lesser General Public License along with this program. If 28 | not, see . */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | struct ext_argument 38 | { 39 | char const *name; 40 | int type; 41 | 42 | static ext_argument required (char const *name) 43 | { return {required_argument, name}; } 44 | 45 | static ext_argument optional (char const *name) 46 | { return {optional_argument, name}; } 47 | 48 | static ext_argument no; 49 | 50 | static std::string 51 | shopt (int has_arg) 52 | { 53 | switch (has_arg) 54 | { 55 | case optional_argument: 56 | return "::"; 57 | case required_argument: 58 | return ":"; 59 | case no_argument: 60 | return ""; 61 | }; 62 | assert (has_arg != has_arg); 63 | abort (); 64 | } 65 | 66 | static std::string 67 | help (int has_arg, char const *name) 68 | { 69 | switch (has_arg) 70 | { 71 | case optional_argument: 72 | return std::string ("[=") + name + "]"; 73 | case required_argument: 74 | return std::string ("=") + name; 75 | case no_argument: 76 | return ""; 77 | }; 78 | assert (has_arg != has_arg); 79 | abort (); 80 | } 81 | 82 | private: 83 | ext_argument (int type, char const *name) 84 | : name {name} 85 | , type {type} 86 | {} 87 | }; 88 | 89 | struct ext_shopt 90 | { 91 | int const code; 92 | 93 | ext_shopt (char code) 94 | : code {code} 95 | {} 96 | 97 | ext_shopt () 98 | : code {gencode ()} 99 | {} 100 | 101 | static std::string 102 | shopt (int c, int has_arg) 103 | { 104 | if (c < 256) 105 | { 106 | char cc = c; 107 | return std::string (&cc, 1) + ext_argument::shopt (has_arg); 108 | } 109 | else 110 | return ""; 111 | } 112 | 113 | static std::string 114 | help (int c) 115 | { 116 | if (c < 256) 117 | return std::string ("-") + ((char) c); 118 | else 119 | return ""; 120 | } 121 | 122 | private: 123 | int 124 | gencode () 125 | { 126 | static int last = 256; 127 | return last++; 128 | } 129 | }; 130 | 131 | inline bool 132 | operator== (int c, ext_shopt const &shopt) 133 | { 134 | return c == shopt.code; 135 | } 136 | 137 | struct ext_option 138 | : public option 139 | { 140 | char const *docstring; 141 | char const *arg_name; 142 | 143 | ext_option (ext_shopt shopt, const char *lopt, ext_argument arg, 144 | char const *docstring) 145 | : option {lopt, arg.type, nullptr, shopt.code} 146 | , docstring {docstring} 147 | , arg_name {arg.name} 148 | {} 149 | 150 | std::string 151 | shopt () const 152 | { 153 | return ext_shopt::shopt (val, has_arg); 154 | } 155 | }; 156 | 157 | std::map , std::string>> 158 | merge_options (std::vector const &ext_opts); 159 | 160 | extern ext_shopt help, version, longarg; 161 | extern std::vector ext_options; 162 | -------------------------------------------------------------------------------- /known-dwarf.awk: -------------------------------------------------------------------------------- 1 | #!/bin/gawk -f 2 | 3 | ## Copyright (C) 2012, 2015 Red Hat, Inc. 4 | ## 5 | ## This file is part of elfutils. 6 | ## 7 | ## This file is free software; you can redistribute it and/or modify 8 | ## it under the terms of the GNU General Public License as published by 9 | ## the Free Software Foundation; either version 3 of the License, or 10 | ## (at your option) any later version. 11 | ## 12 | ## elfutils is distributed in the hope that it will be useful, but 13 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ## GNU General Public License for more details. 16 | ## 17 | ## You should have received a copy of the GNU General Public License 18 | ## along with this program. If not, see . 19 | 20 | $1 == "enum" { set = ""; next } 21 | 22 | set == "" && $1 ~ /DW_([A-Z_]+)_([^ ]+)/ { 23 | set = $1; 24 | sub(/^DW_/, "", set); 25 | sub(/_[^[:upper:]_].*$/, "", set); 26 | if (set ~ /LANG_.+/) set = "LANG"; 27 | } 28 | 29 | $1 ~ /DW([_A-Z]+)_([^ ]+)/ { 30 | match($1, ("DW_" set "_([^ ]+)"), fields); 31 | elt = fields[1]; 32 | if (set in DW) 33 | DW[set] = DW[set] "," elt; 34 | else 35 | DW[set] = elt; 36 | } 37 | 38 | END { 39 | print "/* Generated by config/known-dwarf.awk from libdw/dwarf.h contents. */"; 40 | n = asorti(DW, sets); 41 | for (i = 1; i <= n; ++i) { 42 | set = sets[i]; 43 | if (what && what != set) continue; 44 | split(DW[set], elts, ","); 45 | m = asort(elts); 46 | if (m == 0) continue; 47 | print "\n#define DWARF_ALL_KNOWN_DW_" set " \\"; 48 | for (j = 1; j <= m; ++j) { 49 | elt = elts[j]; 50 | if (elt ~ /(low?|hi|high)_user$/) 51 | continue; 52 | print " DWARF_ONE_KNOWN_DW_" set " (" elt ", DW_" set "_" elt ") \\"; 53 | } 54 | print " /* End of DW_" set "_*. */"; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /known-elf.awk: -------------------------------------------------------------------------------- 1 | #!/bin/gawk -f 2 | 3 | ## Copyright (C) 2015 Red Hat, Inc. 4 | ## 5 | ## This file is part of elfutils. 6 | ## 7 | ## This file is free software; you can redistribute it and/or modify 8 | ## it under the terms of the GNU General Public License as published by 9 | ## the Free Software Foundation; either version 3 of the License, or 10 | ## (at your option) any later version. 11 | ## 12 | ## elfutils is distributed in the hope that it will be useful, but 13 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ## GNU General Public License for more details. 16 | ## 17 | ## You should have received a copy of the GNU General Public License 18 | ## along with this program. If not, see . 19 | 20 | $1 == "#define" { 21 | if (match($2, "^(ELFOSABI|ET|EM|SHN|SHT|STB|STT" \ 22 | "|STV|PT|DT|AT|ELF_NOTE_OS|R)_([A-Z0-9_]*)$", fields) \ 23 | && ! match($2, "(_NUM|(LO|HI)(OS|PROC|RESERVE)|RNG(LO|HI))$") \ 24 | && ! match($2, "^(DT_ENCODING|DT_(PROC|VAL|ADDR|VERSIONTAG|EXTRA)NUM)$")) 25 | { 26 | set = fields[1]; 27 | elt = fields[2]; 28 | if (set in KNOWN) 29 | KNOWN[set] = KNOWN[set] "," elt; 30 | else 31 | KNOWN[set] = elt; 32 | 33 | if (set == "EM" && elt != "NONE") { 34 | if (ARCHES) { 35 | ARCHES = ARCHES "," elt 36 | ARCHES_RE = ARCHES_RE "|^" elt "_" 37 | } else { 38 | ARCHES = elt 39 | ARCHES_RE = "^" elt "_" 40 | } 41 | } 42 | } 43 | } 44 | 45 | function emit(set, elt) { 46 | print " ELF_ONE_KNOWN_" set " (" elt ", " set "_" elt ") \\"; 47 | } 48 | 49 | END { 50 | print "/* Generated by config/known-elf.awk from libelf/elf.h contents. */"; 51 | split(ARCHES, arches, ","); 52 | a = asort(arches) 53 | n = asorti(KNOWN, sets); 54 | for (i = 1; i <= n; ++i) { 55 | set = sets[i]; 56 | split(KNOWN[set], elts, ","); 57 | m = asort(elts); 58 | if (m == 0) 59 | continue; 60 | print "\n#define ELF_ALL_KNOWN_" set " \\"; 61 | 62 | delete known2 63 | for (j = 1; j <= m; ++j) { 64 | elt = elts[j]; 65 | found = 0; 66 | if (set != "ELFOSABI" && set != "EM") { 67 | # R_ names some architectures in a funny way. Translate the 68 | # architecture key back for consistency's sake. The 69 | # enumerator with the mangled architecture name is still 70 | # passed to ELF_ONE_KNOWN_R* invocation. 71 | if (set "_" elt ~ "^R_390_") { 72 | found = 1; 73 | arch = "S390"; 74 | } else if (set "_" elt ~ "^R_IA64_") { 75 | found = 1; 76 | arch = "IA_64"; 77 | 78 | } else { 79 | for (k = 1; k <= a; ++k) { 80 | arch = arches[k]; 81 | if (elt ~ "^" arches[k] "_") { 82 | found = 1; 83 | break; 84 | } 85 | } 86 | } 87 | 88 | if (found) { 89 | if (arch in known2) 90 | known2[arch] = known2[arch] "," elt; 91 | else 92 | known2[arch] = elt; 93 | } 94 | } 95 | 96 | if (! found) 97 | emit(set, elt); 98 | } 99 | 100 | a2 = asorti(known2, used_arches); 101 | if (a2 == 0) 102 | continue; 103 | 104 | print "\n#define ELF_ALL_KNOWN_" set "_ARCHES \\"; 105 | for (k = 1; k <= a2; ++k) 106 | print " ELF_ONE_KNOWN_" set "_ARCH (" used_arches[k] ") \\" 107 | 108 | for (k = 1; k <= a2; ++k) { 109 | arch = used_arches[k]; 110 | set2 = set "_" arch 111 | split(known2[arch], elts2, ","); 112 | m2 = asort(elts2); 113 | if (m2 == 0) 114 | continue; 115 | print "\n#define ELF_ALL_KNOWN_" set2 " \\"; 116 | for (j2 = 1; j2 <= m2; ++j2) { 117 | elt2 = elts2[j2]; 118 | emit(set, elt2); 119 | } 120 | } 121 | } 122 | 123 | print "" 124 | } 125 | -------------------------------------------------------------------------------- /libzwerg/atval.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014, 2015 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #ifndef _ATVAL_H_ 30 | #define _ATVAL_H_ 31 | 32 | #include "dwfl_context.hh" 33 | #include "op.hh" 34 | 35 | #include "value-dw.hh" 36 | #include "value-aset.hh" 37 | 38 | // Obtain a value of ATTR at DIE. 39 | std::unique_ptr > 40 | at_value (std::shared_ptr dwctx, 41 | value_die const &die, Dwarf_Attribute attr); 42 | 43 | // Obtain DIE's ranges. 44 | value_aset die_ranges (Dwarf_Die die); 45 | 46 | std::unique_ptr > 47 | dwop_number (std::shared_ptr dwctx, 48 | Dwarf_Attribute const &attr, Dwarf_Op const *op); 49 | 50 | std::unique_ptr > 51 | dwop_number2 (std::shared_ptr dwctx, 52 | Dwarf_Attribute const &attr, Dwarf_Op const *op); 53 | 54 | #endif /* _ATVAL_H_ */ 55 | -------------------------------------------------------------------------------- /libzwerg/bindings.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #ifndef _BINDINGS_H_ 30 | #define _BINDINGS_H_ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | struct op_bind; 38 | struct builtin; 39 | struct vocabulary; 40 | 41 | class binding 42 | { 43 | op_bind *m_bind; 44 | builtin const *m_bi; 45 | 46 | public: 47 | binding (op_bind &bind); 48 | binding (builtin const &bi); 49 | 50 | bool is_builtin () const 51 | { return m_bi != nullptr; } 52 | 53 | op_bind &get_bind () const; 54 | builtin const &get_builtin () const; 55 | }; 56 | 57 | class bindings 58 | { 59 | std::map m_bindings; 60 | bindings *m_super; 61 | 62 | public: 63 | bindings () 64 | : m_super {nullptr} 65 | {} 66 | 67 | explicit bindings (bindings &super) 68 | : m_super {&super} 69 | {} 70 | 71 | explicit bindings (vocabulary const &voc); 72 | 73 | void bind (std::string name, op_bind &op); 74 | binding const *find (std::string name); 75 | std::vector names () const; 76 | std::vector names_closure () const; 77 | }; 78 | 79 | class upref 80 | { 81 | bool m_id_used; 82 | unsigned m_id; 83 | builtin const *m_bi; 84 | 85 | explicit upref (builtin const *bi); 86 | 87 | public: 88 | explicit upref (binding const &bn); 89 | static upref from (upref const &other); 90 | 91 | bool is_builtin () const 92 | { return m_bi != nullptr; } 93 | 94 | void mark_used (unsigned id); 95 | bool is_id_used () const; 96 | unsigned get_id () const; 97 | builtin const &get_builtin () const; 98 | }; 99 | 100 | class uprefs 101 | { 102 | std::map m_ids; 103 | unsigned m_nextid; 104 | 105 | public: 106 | uprefs (); 107 | uprefs (bindings &bns, uprefs &super); 108 | 109 | upref *find (std::string name); 110 | std::map refd_ids () const; 111 | }; 112 | 113 | #endif//_BINDINGS_H_ 114 | -------------------------------------------------------------------------------- /libzwerg/build-version-script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ libzwerg.map -ot $1/libzwerg.map ]; then 4 | cp $1/libzwerg.map libzwerg.map && rm -f libzwerg.so 5 | else 6 | true 7 | fi 8 | -------------------------------------------------------------------------------- /libzwerg/builtin-closure.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | Copyright (C) 2014 Red Hat, Inc. 4 | This file is part of dwgrep. 5 | 6 | This file is free software; you can redistribute it and/or modify 7 | it under the terms of either 8 | 9 | * the GNU Lesser General Public License as published by the Free 10 | Software Foundation; either version 3 of the License, or (at 11 | your option) any later version 12 | 13 | or 14 | 15 | * the GNU General Public License as published by the Free 16 | Software Foundation; either version 2 of the License, or (at 17 | your option) any later version 18 | 19 | or both in parallel, as here. 20 | 21 | dwgrep is distributed in the hope that it will be useful, but 22 | WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | General Public License for more details. 25 | 26 | You should have received copies of the GNU General Public License and 27 | the GNU Lesser General Public License along with this program. If 28 | not, see . */ 29 | 30 | #include 31 | 32 | #include "builtin-closure.hh" 33 | #include "value-closure.hh" 34 | #include "scon.hh" 35 | 36 | // State for the sub-program that the apply executes. This gets constructed each 37 | // time a new program is pulled from upstream, then used to fetch stacks to 38 | // yield, and then torn down. 39 | struct op_apply::substate 40 | { 41 | std::unique_ptr m_value; 42 | scon m_scon; 43 | scon_guard m_sg; 44 | 45 | substate (stack::uptr stk) 46 | : m_value {static_cast (stk->pop ().release ())} 47 | , m_scon {m_value->get_layout ()} 48 | , m_sg {m_scon, m_value->get_op ()} 49 | { 50 | m_scon.con (m_value->get_rdv_ll (), 51 | std::ref (*m_value)); 52 | m_value->get_origin ().set_next (m_scon, std::move (stk)); 53 | } 54 | 55 | stack::uptr 56 | next () 57 | { 58 | return m_value->get_op ().next (m_scon); 59 | } 60 | }; 61 | 62 | // State for this operation. 63 | struct op_apply::state 64 | { 65 | std::unique_ptr m_substate; 66 | }; 67 | 68 | op_apply::op_apply (layout &l, std::shared_ptr upstream, 69 | bool skip_non_closures) 70 | : m_upstream {upstream} 71 | , m_skip_non_closures {skip_non_closures} 72 | , m_ll {l.reserve ()} 73 | {} 74 | 75 | std::string 76 | op_apply::name () const 77 | { 78 | return "apply"; 79 | } 80 | 81 | void 82 | op_apply::state_con (scon &sc) const 83 | { 84 | sc.con (m_ll); 85 | m_upstream->state_con (sc); 86 | } 87 | 88 | void 89 | op_apply::state_des (scon &sc) const 90 | { 91 | m_upstream->state_des (sc); 92 | sc.des (m_ll); 93 | } 94 | 95 | stack::uptr 96 | op_apply::next (scon &sc) const 97 | { 98 | state &st = sc.get (m_ll); 99 | while (true) 100 | { 101 | while (st.m_substate == nullptr) 102 | if (auto stk = m_upstream->next (sc)) 103 | { 104 | if (! stk->top ().is ()) 105 | { 106 | if (m_skip_non_closures) 107 | return stk; 108 | 109 | std::cerr << "Error: `apply' expects a T_CLOSURE on TOS.\n"; 110 | continue; 111 | } 112 | 113 | st.m_substate = std::make_unique (std::move (stk)); 114 | } 115 | else 116 | return nullptr; 117 | 118 | if (auto stk = st.m_substate->next ()) 119 | return stk; 120 | 121 | st.m_substate = nullptr; 122 | } 123 | } 124 | 125 | std::shared_ptr 126 | builtin_apply::build_exec (layout &l, std::shared_ptr upstream) const 127 | { 128 | return std::make_shared (l, upstream); 129 | } 130 | 131 | char const * 132 | builtin_apply::name () const 133 | { 134 | return "apply"; 135 | } 136 | 137 | std::string 138 | builtin_apply::docstring () const 139 | { 140 | return "@hide"; 141 | } 142 | -------------------------------------------------------------------------------- /libzwerg/builtin-closure.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | Copyright (C) 2014 Red Hat, Inc. 4 | This file is part of dwgrep. 5 | 6 | This file is free software; you can redistribute it and/or modify 7 | it under the terms of either 8 | 9 | * the GNU Lesser General Public License as published by the Free 10 | Software Foundation; either version 3 of the License, or (at 11 | your option) any later version 12 | 13 | or 14 | 15 | * the GNU General Public License as published by the Free 16 | Software Foundation; either version 2 of the License, or (at 17 | your option) any later version 18 | 19 | or both in parallel, as here. 20 | 21 | dwgrep is distributed in the hope that it will be useful, but 22 | WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | General Public License for more details. 25 | 26 | You should have received copies of the GNU General Public License and 27 | the GNU Lesser General Public License along with this program. If 28 | not, see . */ 29 | 30 | #ifndef _BUILTIN_CLOSURE_H_ 31 | #define _BUILTIN_CLOSURE_H_ 32 | 33 | #include "op.hh" 34 | #include "builtin.hh" 35 | 36 | class value_closure; 37 | 38 | // Pop closure, execute it. 39 | class op_apply 40 | : public op 41 | { 42 | struct state; 43 | struct substate; 44 | std::shared_ptr m_upstream; 45 | bool m_skip_non_closures; 46 | layout::loc m_ll; 47 | 48 | public: 49 | // When skip_non_closures is true and the incoming stack doesn't have a 50 | // closure on TOS, op_apply lets it pass through. Otherwise it complains. 51 | op_apply (layout &l, std::shared_ptr upstream, bool skip_non_closures = false); 52 | 53 | std::string name () const override; 54 | void state_con (scon &sc) const override; 55 | void state_des (scon &sc) const override; 56 | stack::uptr next (scon &sc) const override; 57 | 58 | // Rendezvous state. Rendezvous is an area at the beginning of substate where 59 | // the closure being executed is stored. 60 | struct rendezvous 61 | { 62 | value_closure &closure; 63 | 64 | rendezvous (value_closure &closure) 65 | : closure {closure} 66 | {} 67 | }; 68 | 69 | static layout::loc 70 | reserve_rendezvous (layout &l) 71 | { 72 | return l.reserve (); 73 | } 74 | }; 75 | 76 | struct builtin_apply 77 | : public builtin 78 | { 79 | std::shared_ptr build_exec (layout &l, std::shared_ptr upstream) 80 | const override; 81 | 82 | char const *name () const override; 83 | std::string docstring () const override; 84 | }; 85 | 86 | #endif /* _BUILTIN_CLOSURE_H_ */ 87 | -------------------------------------------------------------------------------- /libzwerg/builtin-cmp.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | Copyright (C) 2014 Red Hat, Inc. 4 | This file is part of dwgrep. 5 | 6 | This file is free software; you can redistribute it and/or modify 7 | it under the terms of either 8 | 9 | * the GNU Lesser General Public License as published by the Free 10 | Software Foundation; either version 3 of the License, or (at 11 | your option) any later version 12 | 13 | or 14 | 15 | * the GNU General Public License as published by the Free 16 | Software Foundation; either version 2 of the License, or (at 17 | your option) any later version 18 | 19 | or both in parallel, as here. 20 | 21 | dwgrep is distributed in the hope that it will be useful, but 22 | WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | General Public License for more details. 25 | 26 | You should have received copies of the GNU General Public License and 27 | the GNU Lesser General Public License along with this program. If 28 | not, see . */ 29 | 30 | #ifndef _BUILTIN_CMP_H_ 31 | #define _BUILTIN_CMP_H_ 32 | 33 | #include "builtin.hh" 34 | 35 | struct builtin_eq 36 | : public pred_builtin 37 | { 38 | using pred_builtin::pred_builtin; 39 | 40 | std::unique_ptr build_pred (layout &l) const override; 41 | 42 | char const *name () const override; 43 | std::string docstring () const override; 44 | }; 45 | 46 | struct builtin_lt 47 | : public pred_builtin 48 | { 49 | using pred_builtin::pred_builtin; 50 | 51 | std::unique_ptr build_pred (layout &l) const override; 52 | 53 | char const *name () const override; 54 | std::string docstring () const override; 55 | }; 56 | 57 | struct builtin_gt 58 | : public pred_builtin 59 | { 60 | using pred_builtin::pred_builtin; 61 | 62 | std::unique_ptr build_pred (layout &l) const override; 63 | 64 | char const *name () const override; 65 | std::string docstring () const override; 66 | }; 67 | 68 | #endif /* _BUILTIN_CMP_H_ */ 69 | -------------------------------------------------------------------------------- /libzwerg/builtin-cst.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017, 2018 Petr Machata 3 | Copyright (C) 2014 Red Hat, Inc. 4 | This file is part of dwgrep. 5 | 6 | This file is free software; you can redistribute it and/or modify 7 | it under the terms of either 8 | 9 | * the GNU Lesser General Public License as published by the Free 10 | Software Foundation; either version 3 of the License, or (at 11 | your option) any later version 12 | 13 | or 14 | 15 | * the GNU General Public License as published by the Free 16 | Software Foundation; either version 2 of the License, or (at 17 | your option) any later version 18 | 19 | or both in parallel, as here. 20 | 21 | dwgrep is distributed in the hope that it will be useful, but 22 | WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | General Public License for more details. 25 | 26 | You should have received copies of the GNU General Public License and 27 | the GNU Lesser General Public License along with this program. If 28 | not, see . */ 29 | 30 | #ifndef _BUILTIN_CST_H_ 31 | #define _BUILTIN_CST_H_ 32 | 33 | #include 34 | 35 | #include "builtin.hh" 36 | #include "op.hh" 37 | #include "value.hh" 38 | 39 | class builtin_constant 40 | : public builtin 41 | { 42 | std::unique_ptr m_value; 43 | 44 | public: 45 | explicit builtin_constant (std::unique_ptr &&value) 46 | : m_value {std::move (value)} 47 | {} 48 | 49 | std::shared_ptr build_exec (layout &l, std::shared_ptr upstream) 50 | const override; 51 | 52 | char const *name () const override; 53 | 54 | std::string docstring () const override; 55 | }; 56 | 57 | struct builtin_hex 58 | : public builtin 59 | { 60 | std::shared_ptr build_exec (layout &l, std::shared_ptr upstream) 61 | const override; 62 | 63 | char const *name () const override; 64 | std::string docstring () const override; 65 | }; 66 | 67 | struct builtin_dec 68 | : public builtin 69 | { 70 | std::shared_ptr build_exec (layout &l, std::shared_ptr upstream) 71 | const override; 72 | 73 | char const *name () const override; 74 | std::string docstring () const override; 75 | }; 76 | 77 | struct builtin_oct 78 | : public builtin 79 | { 80 | std::shared_ptr build_exec (layout &l, std::shared_ptr upstream) 81 | const override; 82 | 83 | char const *name () const override; 84 | std::string docstring () const override; 85 | }; 86 | 87 | struct builtin_bin 88 | : public builtin 89 | { 90 | std::shared_ptr build_exec (layout &l, std::shared_ptr upstream) 91 | const override; 92 | 93 | char const *name () const override; 94 | std::string docstring () const override; 95 | }; 96 | 97 | struct builtin_pred_pos 98 | : public pred_builtin 99 | { 100 | size_t m_pos; 101 | 102 | public: 103 | builtin_pred_pos (bool positive, size_t pos) 104 | : pred_builtin (positive) 105 | , m_pos (pos) 106 | {} 107 | 108 | std::unique_ptr build_pred (layout &l) const override; 109 | 110 | char const *name () const override; 111 | std::string docstring () const override; 112 | }; 113 | 114 | struct op_type 115 | : public inner_op 116 | { 117 | using inner_op::inner_op; 118 | stack::uptr next (scon &sc) const override; 119 | 120 | std::string name () const override final; 121 | static std::string docstring (); 122 | }; 123 | 124 | struct op_pos 125 | : public inner_op 126 | { 127 | using inner_op::inner_op; 128 | stack::uptr next (scon &sc) const override; 129 | 130 | std::string name () const override final; 131 | static std::string docstring (); 132 | }; 133 | 134 | #endif /* _BUILTIN_CST_H_ */ 135 | -------------------------------------------------------------------------------- /libzwerg/builtin-shf.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017, 2018 Petr Machata 3 | Copyright (C) 2014 Red Hat, Inc. 4 | This file is part of dwgrep. 5 | 6 | This file is free software; you can redistribute it and/or modify 7 | it under the terms of either 8 | 9 | * the GNU Lesser General Public License as published by the Free 10 | Software Foundation; either version 3 of the License, or (at 11 | your option) any later version 12 | 13 | or 14 | 15 | * the GNU General Public License as published by the Free 16 | Software Foundation; either version 2 of the License, or (at 17 | your option) any later version 18 | 19 | or both in parallel, as here. 20 | 21 | dwgrep is distributed in the hope that it will be useful, but 22 | WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | General Public License for more details. 25 | 26 | You should have received copies of the GNU General Public License and 27 | the GNU Lesser General Public License along with this program. If 28 | not, see . */ 29 | 30 | #include "builtin-shf.hh" 31 | #include "op.hh" 32 | 33 | namespace 34 | { 35 | char const *const shf_docstring = R"docstring( 36 | 37 | These words reorder elements on stack according to the following 38 | schemes: 39 | 40 | +------+---------+-----------+ 41 | | op | before | after | 42 | +======+=========+===========+ 43 | | dup | A B C D | A B C D D | 44 | +------+---------+-----------+ 45 | | over | A B C D | A B C D C | 46 | +------+---------+-----------+ 47 | | swap | A B C D | A B D C | 48 | +------+---------+-----------+ 49 | | rot | A B C D | A C D B | 50 | +------+---------+-----------+ 51 | | drop | A B C D | A B C | 52 | +------+---------+-----------+ 53 | 54 | Realistically, most of what end users should write will be an 55 | occasional dup or drop. Most of the stack reorganization effects can 56 | be described more clearly using bindings and sub-expressions. But the 57 | operators are present for completeness' sake. 58 | 59 | )docstring"; 60 | } 61 | 62 | stack::uptr 63 | op_drop::next (scon &sc) const 64 | { 65 | if (auto stk = m_upstream->next (sc)) 66 | { 67 | stk->pop (); 68 | return stk; 69 | } 70 | return nullptr; 71 | } 72 | 73 | std::string 74 | op_drop::name () const 75 | { 76 | return "drop"; 77 | } 78 | 79 | std::string 80 | op_drop::docstring () 81 | { 82 | return shf_docstring; 83 | } 84 | 85 | 86 | stack::uptr 87 | op_swap::next (scon &sc) const 88 | { 89 | if (auto stk = m_upstream->next (sc)) 90 | { 91 | auto a = stk->pop (); 92 | auto b = stk->pop (); 93 | stk->push (std::move (a)); 94 | stk->push (std::move (b)); 95 | return stk; 96 | } 97 | return nullptr; 98 | } 99 | 100 | std::string 101 | op_swap::name () const 102 | { 103 | return "swap"; 104 | } 105 | 106 | std::string 107 | op_swap::docstring () 108 | { 109 | return shf_docstring; 110 | } 111 | 112 | 113 | stack::uptr 114 | op_dup::next (scon &sc) const 115 | { 116 | if (auto stk = m_upstream->next (sc)) 117 | { 118 | stk->push (stk->top ().clone ()); 119 | return stk; 120 | } 121 | return nullptr; 122 | } 123 | 124 | std::string 125 | op_dup::name () const 126 | { 127 | return "dup"; 128 | } 129 | 130 | std::string 131 | op_dup::docstring () 132 | { 133 | return shf_docstring; 134 | } 135 | 136 | 137 | stack::uptr 138 | op_over::next (scon &sc) const 139 | { 140 | if (auto stk = m_upstream->next (sc)) 141 | { 142 | stk->push (stk->get (1).clone ()); 143 | return stk; 144 | } 145 | return nullptr; 146 | } 147 | 148 | std::string 149 | op_over::name () const 150 | { 151 | return "over"; 152 | } 153 | 154 | std::string 155 | op_over::docstring () 156 | { 157 | return shf_docstring; 158 | } 159 | 160 | 161 | stack::uptr 162 | op_rot::next (scon &sc) const 163 | { 164 | if (auto stk = m_upstream->next (sc)) 165 | { 166 | auto a = stk->pop (); 167 | auto b = stk->pop (); 168 | auto c = stk->pop (); 169 | stk->push (std::move (b)); 170 | stk->push (std::move (a)); 171 | stk->push (std::move (c)); 172 | return stk; 173 | } 174 | return nullptr; 175 | } 176 | 177 | std::string 178 | op_rot::name () const 179 | { 180 | return "rot"; 181 | } 182 | 183 | std::string 184 | op_rot::docstring () 185 | { 186 | return shf_docstring; 187 | } 188 | -------------------------------------------------------------------------------- /libzwerg/builtin-shf.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017, 2018 Petr Machata 3 | Copyright (C) 2014 Red Hat, Inc. 4 | This file is part of dwgrep. 5 | 6 | This file is free software; you can redistribute it and/or modify 7 | it under the terms of either 8 | 9 | * the GNU Lesser General Public License as published by the Free 10 | Software Foundation; either version 3 of the License, or (at 11 | your option) any later version 12 | 13 | or 14 | 15 | * the GNU General Public License as published by the Free 16 | Software Foundation; either version 2 of the License, or (at 17 | your option) any later version 18 | 19 | or both in parallel, as here. 20 | 21 | dwgrep is distributed in the hope that it will be useful, but 22 | WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | General Public License for more details. 25 | 26 | You should have received copies of the GNU General Public License and 27 | the GNU Lesser General Public License along with this program. If 28 | not, see . */ 29 | 30 | #ifndef _BUILTIN_SHF_H_ 31 | #define _BUILTIN_SHF_H_ 32 | 33 | #include "op.hh" 34 | 35 | struct op_drop 36 | : public inner_op 37 | { 38 | using inner_op::inner_op; 39 | stack::uptr next (scon &sc) const override; 40 | 41 | std::string name () const override final; 42 | static std::string docstring (); 43 | }; 44 | 45 | struct op_swap 46 | : public inner_op 47 | { 48 | using inner_op::inner_op; 49 | stack::uptr next (scon &sc) const override; 50 | 51 | std::string name () const override final; 52 | static std::string docstring (); 53 | }; 54 | 55 | struct op_dup 56 | : public inner_op 57 | { 58 | using inner_op::inner_op; 59 | stack::uptr next (scon &sc) const override; 60 | 61 | std::string name () const override final; 62 | static std::string docstring (); 63 | }; 64 | 65 | struct op_over 66 | : public inner_op 67 | { 68 | using inner_op::inner_op; 69 | stack::uptr next (scon &sc) const override; 70 | 71 | std::string name () const override final; 72 | static std::string docstring (); 73 | }; 74 | 75 | struct op_rot 76 | : public inner_op 77 | { 78 | using inner_op::inner_op; 79 | stack::uptr next (scon &sc) const override; 80 | 81 | std::string name () const override final; 82 | static std::string docstring (); 83 | }; 84 | 85 | #endif /* _BUILTIN_SHF_H_ */ 86 | -------------------------------------------------------------------------------- /libzwerg/builtin-symbol.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | Copyright (C) 2014, 2015 Red Hat, Inc. 4 | This file is part of dwgrep. 5 | 6 | This file is free software; you can redistribute it and/or modify 7 | it under the terms of either 8 | 9 | * the GNU Lesser General Public License as published by the Free 10 | Software Foundation; either version 3 of the License, or (at 11 | your option) any later version 12 | 13 | or 14 | 15 | * the GNU General Public License as published by the Free 16 | Software Foundation; either version 2 of the License, or (at 17 | your option) any later version 18 | 19 | or both in parallel, as here. 20 | 21 | dwgrep is distributed in the hope that it will be useful, but 22 | WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | General Public License for more details. 25 | 26 | You should have received copies of the GNU General Public License and 27 | the GNU Lesser General Public License along with this program. If 28 | not, see . */ 29 | 30 | #include "overload.hh" 31 | #include "value-cst.hh" 32 | #include "value-dw.hh" 33 | #include "value-symbol.hh" 34 | #include "value-str.hh" 35 | 36 | struct op_symbol_dwarf 37 | : public op_yielding_overload 38 | { 39 | using op_yielding_overload::op_yielding_overload; 40 | 41 | std::unique_ptr > 42 | operate (std::unique_ptr val) const override; 43 | 44 | static std::string docstring (); 45 | }; 46 | 47 | struct op_name_symbol 48 | : public op_once_overload 49 | { 50 | using op_once_overload::op_once_overload; 51 | 52 | value_str operate (std::unique_ptr val) const override; 53 | static std::string docstring (); 54 | }; 55 | 56 | struct op_label_symbol 57 | : public op_once_overload 58 | { 59 | using op_once_overload::op_once_overload; 60 | 61 | value_cst operate (std::unique_ptr val) const override; 62 | static std::string docstring (); 63 | }; 64 | 65 | struct op_binding_symbol 66 | : public op_once_overload 67 | { 68 | using op_once_overload::op_once_overload; 69 | 70 | value_cst operate (std::unique_ptr val) const override; 71 | static std::string docstring (); 72 | }; 73 | 74 | struct op_visibility_symbol 75 | : public op_once_overload 76 | { 77 | using op_once_overload::op_once_overload; 78 | 79 | value_cst operate (std::unique_ptr val) const override; 80 | static std::string docstring (); 81 | }; 82 | 83 | struct op_address_symbol 84 | : public op_once_overload 85 | { 86 | using op_once_overload::op_once_overload; 87 | 88 | value_cst operate (std::unique_ptr val) const override; 89 | static std::string docstring (); 90 | }; 91 | 92 | struct op_size_symbol 93 | : public op_once_overload 94 | { 95 | using op_once_overload::op_once_overload; 96 | 97 | value_cst operate (std::unique_ptr val) const override; 98 | static std::string docstring (); 99 | }; 100 | -------------------------------------------------------------------------------- /libzwerg/builtin.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | Copyright (C) 2014 Red Hat, Inc. 4 | This file is part of dwgrep. 5 | 6 | This file is free software; you can redistribute it and/or modify 7 | it under the terms of either 8 | 9 | * the GNU Lesser General Public License as published by the Free 10 | Software Foundation; either version 3 of the License, or (at 11 | your option) any later version 12 | 13 | or 14 | 15 | * the GNU General Public License as published by the Free 16 | Software Foundation; either version 2 of the License, or (at 17 | your option) any later version 18 | 19 | or both in parallel, as here. 20 | 21 | dwgrep is distributed in the hope that it will be useful, but 22 | WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | General Public License for more details. 25 | 26 | You should have received copies of the GNU General Public License and 27 | the GNU Lesser General Public License along with this program. If 28 | not, see . */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #include "builtin.hh" 35 | #include "builtin-cst.hh" 36 | #include "op.hh" 37 | #include "overload.hh" 38 | #include "value-cst.hh" 39 | 40 | std::unique_ptr 41 | builtin::build_pred (layout &l) const 42 | { 43 | return nullptr; 44 | } 45 | 46 | std::shared_ptr 47 | builtin::build_exec (layout &l, std::shared_ptr upstream) const 48 | { 49 | return nullptr; 50 | } 51 | 52 | std::string 53 | builtin::docstring () const 54 | { 55 | return ""; 56 | } 57 | 58 | builtin_protomap 59 | builtin::protomap () const 60 | { 61 | return {}; 62 | } 63 | 64 | std::unique_ptr 65 | maybe_invert (std::unique_ptr pred, bool positive) 66 | { 67 | if (positive) 68 | return pred; 69 | else 70 | return std::make_unique (std::move (pred)); 71 | } 72 | 73 | vocabulary::vocabulary () 74 | : m_builtins {} 75 | {} 76 | 77 | vocabulary::vocabulary (vocabulary const &a, vocabulary const &b) 78 | : vocabulary {} 79 | { 80 | std::set all_names; 81 | for (auto const &builtin: a.m_builtins) 82 | all_names.insert (builtin.first); 83 | for (auto const &builtin: b.m_builtins) 84 | all_names.insert (builtin.first); 85 | 86 | for (auto const &name: all_names) 87 | { 88 | auto ba = a.find (name); 89 | auto bb = b.find (name); 90 | assert (ba != nullptr || bb != nullptr); 91 | 92 | if (ba == nullptr || bb == nullptr) 93 | add (ba != nullptr ? ba : bb, name); 94 | else 95 | { 96 | // Both A and B have this builtin. If both are overloads, 97 | // and each of them has a different set of specializations, 98 | // we can merge. 99 | auto ola = std::dynamic_pointer_cast (ba); 100 | assert (ola != nullptr); 101 | 102 | auto olb = std::dynamic_pointer_cast (bb); 103 | assert (olb != nullptr); 104 | 105 | auto ta = ola->get_overload_tab (); 106 | auto tb = olb->get_overload_tab (); 107 | 108 | // Note: overload tables can be shared. But when we are 109 | // merging vocabularies, they are already a done deal and 110 | // nothing should be added to them, so it shouldn't be a 111 | // problem that we unshare some of the tables. 112 | auto tc = std::make_shared (*ta, *tb); 113 | add (ola->create_merged (tc), name); 114 | } 115 | } 116 | } 117 | 118 | vocabulary::~vocabulary () 119 | {} 120 | 121 | void 122 | vocabulary::add (std::shared_ptr b) 123 | { 124 | add (b, b->name ()); 125 | } 126 | 127 | void 128 | vocabulary::add (std::shared_ptr b, std::string const &name) 129 | { 130 | assert (find (name) == nullptr); 131 | m_builtins.insert (std::make_pair (name, b)); 132 | } 133 | 134 | std::shared_ptr 135 | vocabulary::find (std::string const &name) const 136 | { 137 | auto it = m_builtins.find (name); 138 | if (it == m_builtins.end ()) 139 | return nullptr; 140 | else 141 | return it->second; 142 | } 143 | 144 | void 145 | add_builtin_constant (vocabulary &voc, constant cst, char const *name) 146 | { 147 | auto builtin = std::make_shared 148 | (std::make_unique (cst, 0)); 149 | voc.add (builtin, name); 150 | } 151 | -------------------------------------------------------------------------------- /libzwerg/cache.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include "cache.hh" 34 | #include "dwpp.hh" 35 | #include "dwit.hh" 36 | 37 | void 38 | parent_cache::recursively_populate_unit (unit_cache_t &uc, Dwarf_Die die, 39 | Dwarf_Off paroff) 40 | { 41 | while (true) 42 | { 43 | Dwarf_Off off = dwarf_dieoffset (&die); 44 | uc.push_back (std::make_pair (off, paroff)); 45 | 46 | { 47 | Dwarf_Die child; 48 | if (dwpp_child (die, child)) 49 | recursively_populate_unit (uc, child, off); 50 | } 51 | 52 | switch (dwarf_siblingof (&die, &die)) 53 | { 54 | case 0: 55 | break; 56 | case -1: 57 | throw_libdw (); 58 | case 1: 59 | return; 60 | } 61 | } 62 | } 63 | 64 | parent_cache::unit_cache_t 65 | parent_cache::populate_unit (Dwarf_Die die) 66 | { 67 | unit_cache_t uc; 68 | recursively_populate_unit (uc, die, no_off); 69 | return uc; 70 | } 71 | 72 | Dwarf_Off 73 | parent_cache::find (Dwarf_Die die) 74 | { 75 | Dwarf_Die cudie; 76 | if (dwarf_diecu (&die, &cudie, nullptr, nullptr) == nullptr) 77 | throw_libdw (); 78 | 79 | Dwarf_Off cuoff = dwarf_dieoffset (&cudie); 80 | Dwarf *dw = dwarf_cu_getdwarf (die.cu); 81 | auto key = std::make_pair (dw, cuoff); 82 | 83 | auto it = m_cache.find (key); 84 | if (it == m_cache.end ()) 85 | it = m_cache.insert (std::make_pair (key, populate_unit (cudie))).first; 86 | 87 | Dwarf_Off dieoff = dwarf_dieoffset (&die); 88 | auto jt = std::lower_bound 89 | (it->second.begin (), it->second.end (), dieoff, 90 | [] (std::pair const &a, Dwarf_Off b) 91 | { 92 | return a.first < b; 93 | }); 94 | 95 | assert (jt != it->second.end ()); 96 | assert (jt->first == dieoff); 97 | return jt->second; 98 | } 99 | 100 | 101 | bool 102 | root_cache::is_root (Dwarf_Die die) 103 | { 104 | Dwarf *dw = dwarf_cu_getdwarf (die.cu); 105 | auto it = m_cache.find (dw); 106 | if (it == m_cache.end ()) 107 | { 108 | off_vect v; 109 | for (auto jt = cu_iterator { dw }; jt != cu_iterator::end (); ++jt) 110 | v.push_back (dwarf_dieoffset (*jt)); 111 | 112 | // Populate the cache for this Dwarf. 113 | it = m_cache.insert (std::make_pair (dw, std::move (v))).first; 114 | } 115 | 116 | Dwarf_Off dieoff = dwarf_dieoffset (&die); 117 | auto jt = std::lower_bound (it->second.begin (), it->second.end (), dieoff); 118 | return jt != it->second.end () && *jt == dieoff; 119 | } 120 | -------------------------------------------------------------------------------- /libzwerg/cache.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #ifndef _CACHE_H_ 30 | #define _CACHE_H_ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | 39 | class parent_cache 40 | { 41 | using unit_cache_t = std::vector >; 42 | using cache_t = std::map , unit_cache_t>; 43 | 44 | cache_t m_cache; 45 | 46 | void recursively_populate_unit (unit_cache_t &uc, Dwarf_Die die, 47 | Dwarf_Off paroff); 48 | unit_cache_t populate_unit (Dwarf_Die die); 49 | 50 | public: 51 | static Dwarf_Off const no_off = (Dwarf_Off) -1; 52 | Dwarf_Off find (Dwarf_Die die); 53 | }; 54 | 55 | class root_cache 56 | { 57 | using off_vect = std::vector ; 58 | using cache_t = std::map ; 59 | 60 | cache_t m_cache; 61 | 62 | public: 63 | bool is_root (Dwarf_Die die); 64 | }; 65 | 66 | 67 | #endif /* _CACHE_H_ */ 68 | -------------------------------------------------------------------------------- /libzwerg/docstring.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #include 30 | #include 31 | 32 | #include "docstring.hh" 33 | #include "builtin.hh" 34 | #include "strip.hh" 35 | 36 | namespace 37 | { 38 | void 39 | underline (std::stringstream &ss, char c) 40 | { 41 | size_t n = ss.str ().length (); 42 | ss << "\n" << std::setw (n + 1) << std::setfill (c) << "\n"; 43 | } 44 | 45 | std::string 46 | format_selector (selector const &sel) 47 | { 48 | std::stringstream ss; 49 | auto vts = sel.get_types (); 50 | for (auto itb = vts.begin (), ite = vts.end (), it = itb; it != ite; ++it) 51 | { 52 | if (it != itb) 53 | ss << " "; 54 | ss << "``" << *it << "``"; 55 | } 56 | return ss.str (); 57 | } 58 | 59 | std::string 60 | format_head (selector const &sel, builtin_protomap const &pm) 61 | { 62 | std::stringstream ss; 63 | ss << format_selector (sel); 64 | 65 | // OVL now refers to an individual overload. It ought to 66 | // contain at most one prototype. It might contain none if 67 | // the prototype isn't or for whatever reason can't be 68 | // declared. 69 | assert (pm.size () <= 1); 70 | 71 | if (! pm.empty ()) 72 | { 73 | auto const &pm0 = pm[0]; 74 | switch (std::get <1> (pm0)) 75 | { 76 | case yield::many: 77 | ss << " ``->*``"; 78 | break; 79 | case yield::once: 80 | ss << " ``->``"; 81 | break; 82 | case yield::maybe: 83 | ss << " ``->?``"; 84 | break; 85 | case yield::pred: 86 | break; 87 | } 88 | 89 | for (auto const &vt: std::get <2> (pm0)) 90 | ss << " ``" << vt << "``"; 91 | } 92 | else 93 | ss << " ``-> ???``"; 94 | 95 | return ss.str (); 96 | } 97 | } 98 | 99 | std::pair 100 | format_overload (std::tuple > const &ovl) 101 | { 102 | builtin const &bi = *std::get <1> (ovl); 103 | 104 | // Trim new-lines at the beginning and at the end of docstring. 105 | // They may include these to make it clear what's the raw string 106 | // header, and what's the actual documentation. We don't trim 107 | // spaces though, those are significant. 108 | return std::make_pair (format_head (std::get <0> (ovl), bi.protomap ()), 109 | strip (bi.docstring (), "\n")); 110 | } 111 | 112 | std::vector , std::string>> 113 | doc_deduplicate (std::vector > &entries) 114 | { 115 | // A map from descriptions to operators that fit that description. 116 | std::map > ds; 117 | while (! entries.empty ()) 118 | { 119 | auto entry = std::move (entries.back ()); 120 | entries.pop_back (); 121 | 122 | ds[std::move (entry.second)].push_back (std::move (entry.first)); 123 | } 124 | entries.clear (); 125 | 126 | std::vector , std::string>> ret; 127 | while (! ds.empty ()) 128 | { 129 | ret.push_back (std::make_pair (std::move (ds.begin ()->second), 130 | std::move (ds.begin ()->first))); 131 | ds.erase (ds.begin ()); 132 | } 133 | return ret; 134 | } 135 | 136 | std::string 137 | format_entry_map (std::vector , 138 | std::string>> entries, 139 | char udc, std::string label) 140 | { 141 | std::stringstream ret; 142 | 143 | for (auto const &entry: entries) 144 | { 145 | if (entry.second == "@hide") 146 | continue; 147 | 148 | if (label != "") 149 | { 150 | for (auto const &n: entry.first) 151 | ret << ".. _" << label << ' ' << n << ":\n"; 152 | ret << "\n"; 153 | } 154 | 155 | std::stringstream ss; 156 | bool seen = false; 157 | for (auto const &n: entry.first) 158 | { 159 | ss << (seen ? ", " : "") << n; 160 | seen = true; 161 | } 162 | underline (ss, udc); 163 | ret << ss.str () << "\n" << entry.second << "\n\n"; 164 | } 165 | 166 | return ret.str (); 167 | } 168 | -------------------------------------------------------------------------------- /libzwerg/docstring.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "selector.hh" 35 | 36 | struct builtin; 37 | 38 | // For a given overload, this returns a pair whose first elements is a 39 | // string representation of its prototype, and the second is a 40 | // docstring associated with this overload. These pairs are suitable 41 | // for the following deduplication step (see below). 42 | std::pair 43 | format_overload (std::tuple > const &ovl); 44 | 45 | // Entries are a mapping heading->content. This finds content 46 | // duplicates and merges the corresponding headers. It returns a 47 | // mapping list of heads->content. 48 | std::vector , std::string>> 49 | doc_deduplicate (std::vector > &entries); 50 | 51 | // Formats the map that the above deduplication step returned. 52 | std::string format_entry_map (std::vector , 53 | std::string>> entries, 54 | char udc, std::string label = ""); 55 | -------------------------------------------------------------------------------- /libzwerg/dwcst.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Petr Machata 3 | Copyright (C) 2014, 2015 Red Hat, Inc. 4 | This file is part of dwgrep. 5 | 6 | This file is free software; you can redistribute it and/or modify 7 | it under the terms of either 8 | 9 | * the GNU Lesser General Public License as published by the Free 10 | Software Foundation; either version 3 of the License, or (at 11 | your option) any later version 12 | 13 | or 14 | 15 | * the GNU General Public License as published by the Free 16 | Software Foundation; either version 2 of the License, or (at 17 | your option) any later version 18 | 19 | or both in parallel, as here. 20 | 21 | dwgrep is distributed in the hope that it will be useful, but 22 | WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | General Public License for more details. 25 | 26 | You should have received copies of the GNU General Public License and 27 | the GNU Lesser General Public License along with this program. If 28 | not, see . */ 29 | 30 | #ifndef _DWCST_H_ 31 | #define _DWCST_H_ 32 | 33 | typedef struct zw_cdom constant_dom; 34 | 35 | constant_dom const &dw_tag_dom (); 36 | constant_dom const &dw_attr_dom (); 37 | constant_dom const &dw_form_dom (); 38 | 39 | constant_dom const &dw_access_dom (); 40 | constant_dom const &dw_address_class_dom (); 41 | constant_dom const &dw_calling_convention_dom (); 42 | constant_dom const &dw_decimal_sign_dom (); 43 | constant_dom const &dw_discr_list_dom (); 44 | constant_dom const &dw_encoding_dom (); 45 | constant_dom const &dw_endianity_dom (); 46 | constant_dom const &dw_defaulted_dom (); 47 | constant_dom const &dw_identifier_case_dom (); 48 | constant_dom const &dw_inline_dom (); 49 | constant_dom const &dw_lang_dom (); 50 | constant_dom const &dw_locexpr_opcode_dom (); 51 | constant_dom const &dw_macinfo_dom (); 52 | constant_dom const &dw_macro_dom (); 53 | constant_dom const &dw_ordering_dom (); 54 | constant_dom const &dw_virtuality_dom (); 55 | constant_dom const &dw_visibility_dom (); 56 | 57 | constant_dom const &dw_address_dom (); // Dwarf_Addr 58 | constant_dom const &dw_offset_dom (); // Dwarf_Off 59 | constant_dom const &dw_abbrevcode_dom (); 60 | 61 | #endif /* _DWCST_H_ */ 62 | -------------------------------------------------------------------------------- /libzwerg/dwfl_context.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014, 2015 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #include "dwfl_context.hh" 30 | #include "cache.hh" 31 | #include "dwit.hh" 32 | 33 | struct dwfl_context::pimpl 34 | { 35 | parent_cache m_parcache; 36 | root_cache m_rootcache; 37 | 38 | Dwarf_Off 39 | find_parent (Dwarf_Die die) 40 | { 41 | return m_parcache.find (die); 42 | } 43 | 44 | bool 45 | is_root (Dwarf_Die die) 46 | { 47 | return m_rootcache.is_root (die); 48 | } 49 | }; 50 | 51 | dwfl_context::dwfl_context (std::shared_ptr dwfl) 52 | : m_pimpl {std::make_unique ()} 53 | , m_dwfl {dwfl} 54 | {} 55 | 56 | dwfl_context::~dwfl_context () 57 | {} 58 | 59 | Dwarf_Off 60 | dwfl_context::find_parent (Dwarf_Die die) 61 | { 62 | return m_pimpl->find_parent (die); 63 | } 64 | 65 | bool 66 | dwfl_context::is_root (Dwarf_Die die) 67 | { 68 | return m_pimpl->is_root (die); 69 | } 70 | 71 | int 72 | dwfl_context::get_machine () const 73 | { 74 | int machine = EM_NONE; 75 | GElf_Addr bias; 76 | for (auto it = dwfl_module_iterator {m_dwfl.get ()}; 77 | it != dwfl_module_iterator::end (); ++it) 78 | if (Elf *elf = dwfl_module_getelf (*it, &bias)) 79 | { 80 | GElf_Ehdr ehdr; 81 | if (gelf_getehdr (elf, &ehdr) == nullptr) 82 | throw_libelf (); 83 | assert (machine == EM_NONE || machine == ehdr.e_machine); 84 | machine = ehdr.e_machine; 85 | } 86 | else 87 | throw_libdwfl (); 88 | 89 | // This better be true. That symbol must have come from somewhere. 90 | assert (machine != EM_NONE); 91 | return machine; 92 | } 93 | -------------------------------------------------------------------------------- /libzwerg/dwfl_context.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014, 2015 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #ifndef _DWFL_CONTEXT_H_ 30 | #define _DWFL_CONTEXT_H_ 31 | 32 | #include 33 | #include 34 | 35 | // This represents a Dwfl handle together with some query caches. 36 | class dwfl_context 37 | { 38 | class pimpl; 39 | std::unique_ptr m_pimpl; 40 | std::shared_ptr m_dwfl; 41 | 42 | public: 43 | explicit dwfl_context (std::shared_ptr dwfl); 44 | ~dwfl_context (); 45 | 46 | Dwfl *get_dwfl () 47 | { return &*m_dwfl; } 48 | 49 | Dwarf_Off find_parent (Dwarf_Die die); 50 | bool is_root (Dwarf_Die die); 51 | int get_machine () const; 52 | }; 53 | 54 | #endif /* _DWFL_CONTEXT_H_ */ 55 | -------------------------------------------------------------------------------- /libzwerg/dwmods.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014, 2015 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #include "dwmods.hh" 30 | 31 | #include 32 | #include "dwit.hh" 33 | 34 | std::vector 35 | all_dwarfs (dwfl_context &dwctx) 36 | { 37 | std::vector ret; 38 | std::for_each (dwfl_module_iterator {dwctx.get_dwfl ()}, 39 | dwfl_module_iterator::end (), 40 | [&] (dwfl_module mod) 41 | { 42 | Dwarf *dw = mod.dwarf (); 43 | ret.push_back (dw); 44 | if (Dwarf *alt = dwarf_getalt (dw)) 45 | ret.push_back (alt); 46 | }); 47 | return ret; 48 | } 49 | 50 | bool 51 | maybe_next_dwarf (cu_iterator &cuit, 52 | std::vector ::iterator &it, 53 | std::vector ::iterator const end) 54 | { 55 | while (cuit == cu_iterator::end ()) 56 | if (it == end) 57 | return false; 58 | else 59 | cuit = cu_iterator {*it++}; 60 | return true; 61 | } 62 | -------------------------------------------------------------------------------- /libzwerg/dwmods.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #ifndef DWMODS_H 30 | #define DWMODS_H 31 | 32 | #include 33 | #include "dwfl_context.hh" 34 | #include "dwit.hh" 35 | 36 | std::vector all_dwarfs (dwfl_context &dwctx); 37 | 38 | bool maybe_next_dwarf (cu_iterator &cuit, 39 | std::vector ::iterator &it, 40 | std::vector ::iterator const end); 41 | 42 | #endif /* DWMODS_H */ 43 | -------------------------------------------------------------------------------- /libzwerg/dwpp.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #ifndef _DWPP_H_ 30 | #define _DWPP_H_ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | inline __attribute__ ((noreturn)) void 39 | throw_libdwfl (int dwerr = 0) 40 | { 41 | if (dwerr == 0) 42 | dwerr = dwfl_errno (); 43 | assert (dwerr != 0); 44 | throw std::runtime_error (dwfl_errmsg (dwerr)); 45 | } 46 | 47 | inline __attribute__ ((noreturn)) void 48 | throw_libdw (int dwerr = 0) 49 | { 50 | if (dwerr == 0) 51 | dwerr = dwarf_errno (); 52 | assert (dwerr != 0); 53 | throw std::runtime_error (dwarf_errmsg (dwerr)); 54 | } 55 | 56 | inline __attribute__ ((noreturn)) void 57 | throw_libelf () 58 | { 59 | int elferr = elf_errno (); 60 | assert (elferr != 0); 61 | throw std::runtime_error (elf_errmsg (elferr)); 62 | } 63 | 64 | inline bool 65 | dwpp_siblingof (Dwarf_Die const &die, Dwarf_Die &result) 66 | { 67 | switch (dwarf_siblingof (const_cast (&die), &result)) 68 | { 69 | case -1: 70 | throw_libdw (); 71 | case 0: 72 | return true; 73 | case 1: 74 | return false; 75 | default: 76 | abort (); 77 | } 78 | } 79 | 80 | // Returns true if there was a child. 81 | inline bool 82 | dwpp_child (const Dwarf_Die &die, Dwarf_Die &result) 83 | { 84 | int ret = dwarf_child (const_cast (&die), &result); 85 | if (ret < 0) 86 | throw_libdw (); 87 | return ret == 0; 88 | } 89 | 90 | inline Dwarf_Die 91 | dwpp_offdie (Dwarf *dbg, Dwarf_Off offset) 92 | { 93 | Dwarf_Die result; 94 | if (dwarf_offdie (dbg, offset, &result) == nullptr) 95 | throw_libdw (); 96 | return result; 97 | } 98 | 99 | inline Dwarf_Attribute 100 | dwpp_attr (Dwarf_Die &die, unsigned int search_name) 101 | { 102 | Dwarf_Attribute ret; 103 | if (dwarf_attr (&die, search_name, &ret) == nullptr) 104 | throw_libdw (); 105 | return ret; 106 | } 107 | 108 | inline Dwarf_Off 109 | dwpp_abbrev_offset (Dwarf_Abbrev &abbrev) 110 | { 111 | // Evil, evil hack. But the easiest way to pry offset off ABBREV's 112 | // hands as well, libdw won't help us in this regard. 113 | return reinterpret_cast (abbrev); 114 | } 115 | 116 | inline size_t 117 | dwpp_abbrev_attrcnt (Dwarf_Abbrev &abbrev) 118 | { 119 | size_t ret; 120 | if (dwarf_getattrcnt (&abbrev, &ret) != 0) 121 | throw_libdw (); 122 | return ret; 123 | } 124 | 125 | inline Dwarf_Die 126 | dwpp_cudie (Dwarf_CU &cu) 127 | { 128 | Dwarf_Die cudie; 129 | if (dwarf_cu_die (&cu, &cudie, nullptr, nullptr, 130 | nullptr, nullptr, nullptr, nullptr) == nullptr) 131 | throw_libdw (); 132 | return cudie; 133 | } 134 | 135 | inline Dwarf_Die 136 | dwpp_cudie (Dwarf_Die &die) 137 | { 138 | return dwpp_cudie (*die.cu); 139 | } 140 | 141 | inline Dwarf_Die 142 | dwpp_formref_die (Dwarf_Attribute &at) 143 | { 144 | Dwarf_Die ret; 145 | if (dwarf_formref_die (&at, &ret) == nullptr) 146 | throw_libdw (); 147 | return ret; 148 | } 149 | 150 | inline std::string 151 | dwpp_formstring (Dwarf_Attribute &at) 152 | { 153 | if (char const *name = dwarf_formstring (&at)) 154 | return name; 155 | throw_libdw (); 156 | } 157 | 158 | inline Dwarf_Off 159 | dwpp_cu_abbrev_unit_offset (Dwarf_CU &cu) 160 | { 161 | Dwarf_Die cudie; 162 | Dwarf_Off abbrev_off; 163 | if (dwarf_cu_die (&cu, &cudie, nullptr, &abbrev_off, 164 | nullptr, nullptr, nullptr, nullptr) == nullptr) 165 | throw_libdw (); 166 | 167 | return abbrev_off; 168 | } 169 | 170 | #endif /* _DWPP_H_ */ 171 | -------------------------------------------------------------------------------- /libzwerg/flag_saver.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014, 2015 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #ifndef _FLAG_SAVER_H_ 30 | #define _FLAG_SAVER_H_ 31 | 32 | #include 33 | 34 | class ios_flag_saver 35 | { 36 | std::ios &m_stream; 37 | std::ios::fmtflags m_flags; 38 | char m_fillch; 39 | 40 | public: 41 | explicit ios_flag_saver (std::ios &stream) 42 | : m_stream (stream) 43 | , m_flags {stream.flags ()} 44 | , m_fillch {stream.fill ()} 45 | {} 46 | 47 | ~ios_flag_saver () 48 | { 49 | m_stream.flags (m_flags); 50 | m_stream.fill (m_fillch); 51 | } 52 | }; 53 | 54 | #endif /* _FLAG_SAVER_H_ */ 55 | -------------------------------------------------------------------------------- /libzwerg/init.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #ifndef _INIT_HH_ 30 | #define _INIT_HH_ 31 | 32 | #include 33 | 34 | struct vocabulary; 35 | std::unique_ptr dwgrep_vocabulary_core (); 36 | 37 | #endif /* _INIT_HH_ */ 38 | -------------------------------------------------------------------------------- /libzwerg/int.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014, 2015 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #ifndef _INT_H_ 30 | #define _INT_H_ 31 | 32 | #include 33 | #include 34 | 35 | enum class signedness 36 | { 37 | unsign, 38 | sign, 39 | }; 40 | 41 | struct mpz_class 42 | { 43 | union 44 | { 45 | uint64_t m_u; 46 | int64_t m_i; 47 | }; 48 | 49 | signedness m_sign; 50 | 51 | mpz_class () 52 | : m_u {0} 53 | , m_sign {signedness::unsign} 54 | {} 55 | 56 | mpz_class (uint64_t value, signedness sign) 57 | : m_u {value} 58 | , m_sign {sign} 59 | {} 60 | 61 | mpz_class (mpz_class const &that) = default; 62 | 63 | mpz_class (unsigned long long int value) 64 | : mpz_class {static_cast (value), signedness::unsign} 65 | {} 66 | 67 | mpz_class (unsigned long int value) 68 | : mpz_class {static_cast (value), signedness::unsign} 69 | {} 70 | 71 | mpz_class (unsigned int value) 72 | : mpz_class {static_cast (value), signedness::unsign} 73 | {} 74 | 75 | mpz_class (long long int value) 76 | : mpz_class {static_cast (value), signedness::sign} 77 | {} 78 | 79 | mpz_class (long int value) 80 | : mpz_class {static_cast (value), signedness::sign} 81 | {} 82 | 83 | mpz_class (int value) 84 | : mpz_class {static_cast (value), signedness::sign} 85 | {} 86 | 87 | uint64_t uval () const; 88 | int64_t sval () const; 89 | 90 | void swap (mpz_class &that); 91 | 92 | bool is_signed () const 93 | { return m_sign == signedness::sign; } 94 | 95 | bool is_unsigned () const 96 | { return m_sign == signedness::unsign; } 97 | }; 98 | 99 | std::ostream &operator<< (std::ostream &o, mpz_class value); 100 | 101 | bool operator< (mpz_class v1, mpz_class v2); 102 | bool operator> (mpz_class v1, mpz_class v2); 103 | bool operator<= (mpz_class v1, mpz_class v2); 104 | bool operator>= (mpz_class v1, mpz_class v2); 105 | bool operator== (mpz_class v1, mpz_class v2); 106 | bool operator!= (mpz_class v1, mpz_class v2); 107 | 108 | mpz_class operator- (mpz_class v); 109 | mpz_class operator- (mpz_class v1, mpz_class v2); 110 | mpz_class operator+ (mpz_class v1, mpz_class v2); 111 | mpz_class operator* (mpz_class v1, mpz_class v2); 112 | mpz_class operator/ (mpz_class v1, mpz_class v2); 113 | mpz_class operator% (mpz_class v1, mpz_class v2); 114 | 115 | inline uint64_t 116 | mpz_class::uval () const 117 | { 118 | assert (*this >= 0); 119 | return m_u; 120 | } 121 | 122 | inline int64_t 123 | mpz_class::sval () const 124 | { 125 | assert (m_sign == signedness::sign 126 | || m_u <= INT64_MAX); 127 | return m_i; 128 | } 129 | 130 | #endif /* _INT_H_ */ 131 | -------------------------------------------------------------------------------- /libzwerg/known-dwarf-macro-gnu.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #ifndef DWARF_ALL_KNOWN_DW_MACRO_GNU 30 | # define DWARF_ALL_KNOWN_DW_MACRO_GNU \ 31 | DWARF_ONE_KNOWN_DW_MACRO_GNU (define, DW_MACRO_GNU_define) \ 32 | DWARF_ONE_KNOWN_DW_MACRO_GNU (define_indirect, DW_MACRO_GNU_define_indirect) \ 33 | DWARF_ONE_KNOWN_DW_MACRO_GNU (end_file, DW_MACRO_GNU_end_file) \ 34 | DWARF_ONE_KNOWN_DW_MACRO_GNU (start_file, DW_MACRO_GNU_start_file) \ 35 | DWARF_ONE_KNOWN_DW_MACRO_GNU (transparent_include, DW_MACRO_GNU_transparent_include) \ 36 | DWARF_ONE_KNOWN_DW_MACRO_GNU (undef, DW_MACRO_GNU_undef) \ 37 | DWARF_ONE_KNOWN_DW_MACRO_GNU (undef_indirect, DW_MACRO_GNU_undef_indirect) \ 38 | /* End of DW_MACRO_GNU_*. */ 39 | #endif 40 | -------------------------------------------------------------------------------- /libzwerg/layout.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #include "layout.hh" 30 | 31 | namespace 32 | { 33 | size_t 34 | align (size_t top, size_t align) 35 | { 36 | return (top + (align - 1)) & -align; 37 | } 38 | } 39 | 40 | layout::loc 41 | layout::reserve (size_t size, size_t align) 42 | { 43 | m_size = ::align (m_size, align); 44 | auto ret = loc {m_size}; 45 | m_size += size; 46 | return ret; 47 | } 48 | 49 | void 50 | layout::add_union (std::vector layouts) 51 | { 52 | for (auto const &layout: layouts) 53 | if (layout.m_size > m_size) 54 | m_size = layout.m_size; 55 | } 56 | 57 | size_t 58 | layout::size () const 59 | { 60 | return m_size; 61 | } 62 | -------------------------------------------------------------------------------- /libzwerg/layout.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #ifndef _LAYOUT_HH_ 30 | #define _LAYOUT_HH_ 31 | 32 | #include 33 | #include 34 | 35 | class layout 36 | { 37 | size_t m_size; 38 | 39 | public: 40 | struct loc 41 | { 42 | size_t m_loc; 43 | 44 | loc (size_t loc) 45 | : m_loc {loc} 46 | {} 47 | }; 48 | 49 | explicit layout (size_t size = 0) 50 | : m_size {size} 51 | {} 52 | 53 | layout::loc reserve (size_t size, size_t align); 54 | void add_union (std::vector layouts); 55 | template layout::loc reserve (); 56 | 57 | size_t size () const; 58 | }; 59 | 60 | template 61 | layout::loc 62 | layout::reserve () 63 | { 64 | return reserve (sizeof (State), alignof (State)); 65 | } 66 | 67 | #endif // _LAYOUT_HH_ 68 | -------------------------------------------------------------------------------- /libzwerg/libzwerg.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Red Hat, Inc. 3 | 4 | This file is free software; you can redistribute it and/or modify 5 | it under the terms of either 6 | 7 | * the GNU Lesser General Public License as published by the Free 8 | Software Foundation; either version 3 of the License, or (at 9 | your option) any later version 10 | 11 | or 12 | 13 | * the GNU General Public License as published by the Free 14 | Software Foundation; either version 2 of the License, or (at 15 | your option) any later version 16 | 17 | or both in parallel, as here. 18 | 19 | dwgrep is distributed in the hope that it will be useful, but 20 | WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | General Public License for more details. 23 | 24 | You should have received copies of the GNU General Public License and 25 | the GNU Lesser General Public License along with this program. If 26 | not, see . */ 27 | 28 | #ifndef LIBZWERG_HH_ 29 | #define LIBZWERG_HH_ 30 | 31 | #include 32 | #include 33 | 34 | struct zw_deleter 35 | { 36 | void 37 | operator() (zw_value *value) 38 | { 39 | zw_value_destroy (value); 40 | } 41 | 42 | void 43 | operator() (zw_vocabulary *voc) 44 | { 45 | zw_vocabulary_destroy (voc); 46 | } 47 | 48 | void 49 | operator() (zw_query *q) 50 | { 51 | zw_query_destroy (q); 52 | } 53 | 54 | void 55 | operator() (zw_stack *stk) 56 | { 57 | zw_stack_destroy (stk); 58 | } 59 | 60 | void 61 | operator() (zw_result *res) 62 | { 63 | zw_result_destroy (res); 64 | } 65 | }; 66 | 67 | struct zw_throw_on_error 68 | { 69 | zw_error *m_err; 70 | 71 | zw_throw_on_error () 72 | : m_err {nullptr} 73 | {} 74 | 75 | operator zw_error ** () 76 | { 77 | return &m_err; 78 | } 79 | 80 | ~zw_throw_on_error () noexcept (false) 81 | { 82 | if (m_err != nullptr) 83 | { 84 | std::string msg = zw_error_message (m_err); 85 | zw_error_destroy (m_err); 86 | throw std::runtime_error (msg); 87 | } 88 | } 89 | }; 90 | 91 | inline std::unique_ptr 92 | zw_result_next (zw_result &result) 93 | { 94 | zw_stack *stk; 95 | zw_result_next (&result, &stk, zw_throw_on_error {}); 96 | return std::unique_ptr {stk}; 97 | } 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /libzwerg/libzwerg.map: -------------------------------------------------------------------------------- 1 | LIBZWERG_0.1 { 2 | global: 3 | zw_error_destroy; 4 | zw_error_message; 5 | 6 | zw_vocabulary_init; 7 | zw_vocabulary_destroy; 8 | zw_vocabulary_core; 9 | zw_vocabulary_dwarf; 10 | zw_vocabulary_add; 11 | 12 | zw_stack_init; 13 | zw_stack_destroy; 14 | zw_stack_push; 15 | zw_stack_push_take; 16 | zw_stack_depth; 17 | zw_stack_at; 18 | 19 | zw_query_parse; 20 | zw_query_parse_len; 21 | zw_query_destroy; 22 | zw_query_execute; 23 | 24 | zw_result_next; 25 | zw_result_destroy; 26 | 27 | zw_value_pos; 28 | zw_value_destroy; 29 | 30 | zw_value_init_const_i64; 31 | zw_value_init_const_u64; 32 | zw_value_is_const; 33 | zw_value_const_is_signed; 34 | zw_value_const_u64; 35 | zw_value_const_i64; 36 | zw_value_const_format; 37 | zw_value_const_format_brief; 38 | 39 | zw_value_init_str; 40 | zw_value_init_str_len; 41 | zw_value_is_str; 42 | zw_value_str_str; 43 | 44 | zw_value_is_seq; 45 | zw_value_seq_length; 46 | zw_value_seq_at; 47 | 48 | zw_machine_init; 49 | zw_machine_destroy; 50 | zw_machine_code; 51 | 52 | zw_cdom_name; 53 | zw_cdom_is_arith; 54 | zw_cdom_dec; 55 | zw_cdom_hex; 56 | zw_cdom_oct; 57 | zw_cdom_bin; 58 | zw_cdom_bool; 59 | zw_cdom_dw_tag; 60 | zw_cdom_dw_attr; 61 | zw_cdom_dw_form; 62 | zw_cdom_dw_lang; 63 | zw_cdom_dw_macinfo; 64 | zw_cdom_dw_macro; 65 | zw_cdom_dw_inline; 66 | zw_cdom_dw_encoding; 67 | zw_cdom_dw_access; 68 | zw_cdom_dw_visibility; 69 | zw_cdom_dw_virtuality; 70 | zw_cdom_dw_identifier_case; 71 | zw_cdom_dw_calling_convention; 72 | zw_cdom_dw_ordering; 73 | zw_cdom_dw_discr_list; 74 | zw_cdom_dw_decimal_sign; 75 | zw_cdom_dw_locexpr_opcode; 76 | zw_cdom_dw_address_class; 77 | zw_cdom_dw_endianity; 78 | zw_cdom_elfsym_stt; 79 | zw_cdom_elfsym_stb; 80 | zw_cdom_elfsym_stv; 81 | 82 | zw_value_init_dwarf; 83 | zw_value_init_dwarf_raw; 84 | zw_value_is_dwarf; 85 | zw_value_dwarf_dwfl; 86 | zw_value_dwarf_name; 87 | zw_value_dwarf_machine; 88 | 89 | zw_value_is_cu; 90 | zw_value_cu_cu; 91 | zw_value_cu_offset; 92 | 93 | zw_value_is_die; 94 | zw_value_die_die; 95 | zw_value_die_dwarf; 96 | 97 | zw_value_is_attr; 98 | zw_value_attr_attr; 99 | zw_value_attr_dwarf; 100 | 101 | zw_value_is_llelem; 102 | zw_value_llelem_low; 103 | zw_value_llelem_high; 104 | zw_value_llelem_attribute; 105 | zw_value_llelem_expr; 106 | 107 | zw_value_is_llop; 108 | zw_value_llop_attribute; 109 | zw_value_llop_op; 110 | 111 | zw_value_is_aset; 112 | zw_value_aset_length; 113 | zw_value_aset_at; 114 | 115 | zw_value_is_elfsym; 116 | zw_value_elfsym_symidx; 117 | zw_value_elfsym_symbol; 118 | zw_value_elfsym_name; 119 | zw_value_elfsym_dwarf; 120 | 121 | local: 122 | *; 123 | }; 124 | 125 | LIBZWERG_0.4 { 126 | global: 127 | zw_value_clone; 128 | zw_cdom_dw_defaulted; 129 | } LIBZWERG_0.1; 130 | -------------------------------------------------------------------------------- /libzwerg/libzwergP.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | Copyright (C) 2014, 2015 Red Hat, Inc. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #include "libzwerg.h" 30 | #include "libzwerg-dw.h" 31 | 32 | #include 33 | #include 34 | 35 | #include "scon.hh" 36 | #include "tree.hh" 37 | #include "op.hh" 38 | 39 | struct vocabulary; 40 | 41 | struct zw_error 42 | { 43 | std::string m_message; 44 | }; 45 | 46 | struct zw_vocabulary 47 | { 48 | std::unique_ptr m_voc; 49 | }; 50 | 51 | struct zw_query 52 | { 53 | layout m_l; 54 | op_origin &m_origin; 55 | std::shared_ptr m_op; 56 | }; 57 | 58 | struct zw_result 59 | { 60 | std::shared_ptr m_op; 61 | scon m_sc; 62 | scon_guard m_sg; 63 | 64 | zw_result (layout const &l, 65 | op_origin const &origin, std::shared_ptr op, stack::uptr stk) 66 | : m_op {op} 67 | , m_sc {l} 68 | , m_sg {m_sc, *m_op} 69 | { 70 | origin.set_next (m_sc, std::move (stk)); 71 | } 72 | 73 | stack::uptr 74 | next () 75 | { 76 | return m_op->next (m_sc); 77 | } 78 | }; 79 | 80 | struct zw_stack 81 | { 82 | std::vector > m_values; 83 | }; 84 | 85 | 86 | namespace 87 | { 88 | __attribute__ ((unused)) zw_error * 89 | zw_error_new (char const *message) 90 | { 91 | return new zw_error {message}; 92 | } 93 | 94 | template 95 | U 96 | allocate_error (char const *message, U fail_return, zw_error **out_err) 97 | { 98 | assert (out_err != nullptr); 99 | try 100 | { 101 | *out_err = zw_error_new (message); 102 | return fail_return; 103 | } 104 | catch (std::exception const &exc) 105 | { 106 | std::cerr << "Error: " << message << "\n" 107 | << "There was an error while handling that error: " 108 | << exc.what () << "\n" 109 | << "Aborting.\n"; 110 | std::abort (); 111 | } 112 | catch (...) 113 | { 114 | std::cerr << "Error: " << message << "\n" 115 | << "There was an unknown error while handling that error.\n" 116 | << "Aborting.\n"; 117 | std::abort (); 118 | } 119 | } 120 | 121 | template 122 | auto 123 | capture_errors (T &&callback, decltype (callback ()) fail_return, 124 | zw_error **out_err) -> decltype (callback ()) 125 | { 126 | try 127 | { 128 | return callback (); 129 | } 130 | catch (std::exception const &exc) 131 | { 132 | return allocate_error (exc.what (), fail_return, out_err); 133 | } 134 | catch (...) 135 | { 136 | return allocate_error ("unknown error", fail_return, out_err); 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /libzwerg/pred_result.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2022 Petr Machata 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #include 30 | 31 | #include "pred_result.hh" 32 | 33 | std::ostream & 34 | operator<< (std::ostream &o, pred_result result) 35 | { 36 | switch (result) 37 | { 38 | case pred_result::yes: 39 | return o << "yes"; 40 | case pred_result::no: 41 | return o << "no"; 42 | case pred_result::fail: 43 | return o << "fail"; 44 | } 45 | return o; 46 | } 47 | -------------------------------------------------------------------------------- /libzwerg/pred_result.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #ifndef _PRED_RESULT_H_ 30 | #define _PRED_RESULT_H_ 31 | 32 | #include 33 | #include 34 | 35 | enum class pred_result 36 | { 37 | no = false, 38 | yes = true, 39 | fail, 40 | }; 41 | std::ostream &operator<< (std::ostream &o, pred_result result); 42 | 43 | inline pred_result 44 | operator! (pred_result other) 45 | { 46 | switch (other) 47 | { 48 | case pred_result::no: 49 | return pred_result::yes; 50 | case pred_result::yes: 51 | return pred_result::no; 52 | case pred_result::fail: 53 | return pred_result::fail; 54 | } 55 | abort (); 56 | } 57 | 58 | inline pred_result 59 | operator&& (pred_result a, pred_result b) 60 | { 61 | if (a == pred_result::fail || b == pred_result::fail) 62 | return pred_result::fail; 63 | else 64 | return bool (a) && bool (b) ? pred_result::yes : pred_result::no; 65 | } 66 | 67 | inline pred_result 68 | operator|| (pred_result a, pred_result b) 69 | { 70 | if (a == pred_result::fail || b == pred_result::fail) 71 | return pred_result::fail; 72 | else 73 | return bool (a) || bool (b) ? pred_result::yes : pred_result::no; 74 | } 75 | 76 | #endif /* _PRED_RESULT_H_ */ 77 | -------------------------------------------------------------------------------- /libzwerg/scon.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #include "scon.hh" 30 | #include "op.hh" 31 | 32 | scon::scon (layout const &l) 33 | // 85 is 0b1010101, a pattern that's very unlikely to be valid data. If 34 | // op::state_con is not called, this is likely to cause a loud & early 35 | // failure. op_origin relies on this poisoning to detect that the state_con 36 | // chain is interrupted. 37 | : m_buf (l.size (), 85) 38 | {} 39 | 40 | scon_guard::scon_guard (scon_guard &&mv) 41 | : m_sc {mv.m_sc} 42 | , m_op {mv.m_op} 43 | { 44 | mv.m_op = nullptr; 45 | } 46 | 47 | scon_guard::scon_guard (scon &sc, op &op) 48 | : m_sc {sc} 49 | , m_op {&op} 50 | { 51 | m_op->state_con (m_sc); 52 | } 53 | 54 | scon_guard::~scon_guard () 55 | { 56 | // Des is just a destructor wrapper. If it excepts, it's as if a dtor 57 | // excepted, so let it terminate. 58 | if (m_op != nullptr) 59 | m_op->state_des (m_sc); 60 | } 61 | 62 | stack::uptr 63 | scon_guard::next () const 64 | { 65 | return m_op->next (m_sc); 66 | } 67 | -------------------------------------------------------------------------------- /libzwerg/scon.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #ifndef _SCON_H_ 30 | #define _SCON_H_ 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include "layout.hh" 37 | 38 | class scon 39 | { 40 | std::vector m_buf; 41 | 42 | void * 43 | mem (layout::loc loc) 44 | { 45 | return m_buf.data () + loc.m_loc; 46 | } 47 | 48 | public: 49 | scon (layout const &l); 50 | 51 | template 52 | State & 53 | get (layout::loc loc) 54 | { 55 | return *reinterpret_cast (this->mem (loc)); 56 | } 57 | 58 | template 59 | void 60 | con (layout::loc loc, Args const&... args) 61 | { 62 | new (this->mem (loc)) State {args...}; 63 | } 64 | 65 | template 66 | void 67 | des (layout::loc loc) 68 | { 69 | this->get (loc).~State (); 70 | } 71 | 72 | template 73 | void 74 | reset (layout::loc loc, Args const&... args) 75 | { 76 | this->des (loc); 77 | this->con (loc, args...); 78 | } 79 | }; 80 | 81 | class op; 82 | class stack; 83 | struct scon_guard 84 | { 85 | scon &m_sc; 86 | op *m_op; 87 | 88 | scon_guard (scon &sc, op &op); 89 | scon_guard (scon_guard const &cp) = delete; 90 | scon_guard (scon_guard &&mv); 91 | ~scon_guard (); 92 | 93 | std::unique_ptr next () const; 94 | }; 95 | 96 | #endif // _SCON_H_ 97 | -------------------------------------------------------------------------------- /libzwerg/selector.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #include 30 | #include "selector.hh" 31 | #include "stack.hh" 32 | 33 | selector::selector (stack const &s) 34 | : m_imprint {s.profile ()} 35 | , m_mask {0} 36 | {} 37 | 38 | std::vector 39 | selector::get_types () const 40 | { 41 | std::vector ret; 42 | 43 | const unsigned shift = 8 * (sizeof (selector::sel_t) - 1); 44 | for (auto imprint = m_imprint; imprint != 0; imprint <<= 8) 45 | if (uint8_t code = (imprint & (0xff << shift)) >> shift) 46 | ret.push_back (value_type {code}); 47 | 48 | return ret; 49 | } 50 | 51 | std::ostream & 52 | operator<< (std::ostream &o, selector const &sel) 53 | { 54 | bool seen = false; 55 | for (auto const &vt: sel.get_types ()) 56 | { 57 | if (seen) 58 | o << " "; 59 | seen = true; 60 | o << vt.name (); 61 | } 62 | 63 | return o; 64 | } 65 | -------------------------------------------------------------------------------- /libzwerg/selector.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #ifndef _SELECTOR_H_ 30 | #define _SELECTOR_H_ 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include "value.hh" 37 | 38 | struct stack; 39 | 40 | struct selector 41 | { 42 | typedef uint32_t sel_t; 43 | static auto const W = sizeof (sel_t); 44 | 45 | private: 46 | void unused(value_type &v) 47 | { 48 | static_assert (CHAR_BIT == 8, "character has 8 bits"); 49 | static_assert (sizeof (v.code ()) == 1, "sizeof of value_type code is 1"); 50 | } 51 | 52 | sel_t m_imprint; 53 | sel_t m_mask; 54 | 55 | static sel_t 56 | compute_mask () 57 | { 58 | return 0; 59 | } 60 | 61 | template 62 | static sel_t 63 | compute_mask (uint8_t code, Ts... codes) 64 | { 65 | return compute_mask (codes...) >> 8 66 | | (code != 0 ? ((sel_t) 0xff) << (8 * W - 8) : 0); 67 | } 68 | 69 | static sel_t 70 | compute_imprint () 71 | { 72 | return 0; 73 | } 74 | 75 | template 76 | static sel_t 77 | compute_imprint (uint8_t code, Ts... codes) 78 | { 79 | return compute_imprint (codes...) >> 8 80 | | (((sel_t) code) << (8 * W - 8)); 81 | } 82 | 83 | static sel_t 84 | unshift (sel_t sel, size_t N) 85 | { 86 | return sel >> ((W - N) * 8); 87 | } 88 | 89 | public: 90 | template ::type Fake = 0> 92 | selector (Ts... vts) 93 | : m_imprint {unshift (compute_imprint ((vts.code ())...), sizeof... (Ts))} 94 | , m_mask {unshift (compute_mask ((vts.code ())...), sizeof... (Ts))} 95 | {} 96 | 97 | selector (stack const &s); 98 | 99 | selector (selector const &that) 100 | : m_imprint (that.m_imprint) 101 | , m_mask (that.m_mask) 102 | {} 103 | 104 | bool 105 | matches (selector const &profile) const 106 | { 107 | return (profile.m_imprint & m_mask) == m_imprint; 108 | } 109 | 110 | std::vector get_types () const; 111 | 112 | bool operator< (selector const &that) const 113 | { return m_imprint < that.m_imprint; } 114 | bool operator== (selector const &that) const 115 | { return m_imprint == that.m_imprint; } 116 | bool operator!= (selector const &that) const 117 | { return m_imprint != that.m_imprint; } 118 | 119 | friend std::ostream &operator<< (std::ostream &o, selector const &sel); 120 | }; 121 | 122 | std::ostream &operator<< (std::ostream &o, selector const &sel); 123 | 124 | #endif /* _SELECTOR_H_ */ 125 | -------------------------------------------------------------------------------- /libzwerg/stack.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | Copyright (C) 2014, 2015 Red Hat, Inc. 4 | This file is part of dwgrep. 5 | 6 | This file is free software; you can redistribute it and/or modify 7 | it under the terms of either 8 | 9 | * the GNU Lesser General Public License as published by the Free 10 | Software Foundation; either version 3 of the License, or (at 11 | your option) any later version 12 | 13 | or 14 | 15 | * the GNU General Public License as published by the Free 16 | Software Foundation; either version 2 of the License, or (at 17 | your option) any later version 18 | 19 | or both in parallel, as here. 20 | 21 | dwgrep is distributed in the hope that it will be useful, but 22 | WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | General Public License for more details. 25 | 26 | You should have received copies of the GNU General Public License and 27 | the GNU Lesser General Public License along with this program. If 28 | not, see . */ 29 | 30 | #include "stack.hh" 31 | #include "value-closure.hh" 32 | 33 | stack::stack (stack const &that) 34 | : m_profile {that.m_profile} 35 | { 36 | for (auto const &v: that.m_values) 37 | m_values.push_back (v->clone ()); 38 | } 39 | 40 | namespace 41 | { 42 | int 43 | compare_stack (std::vector > const &a, 44 | std::vector > const &b) 45 | { 46 | if (a.size () < b.size ()) 47 | return -1; 48 | else if (a.size () > b.size ()) 49 | return 1; 50 | 51 | // The stack that has nullptr where the other has non-nullptr is 52 | // smaller. 53 | { 54 | auto it = a.begin (); 55 | auto jt = b.begin (); 56 | for (; it != a.end (); ++it, ++jt) 57 | if (*it == nullptr && *jt != nullptr) 58 | return -1; 59 | else if (*it != nullptr && *jt == nullptr) 60 | return 1; 61 | } 62 | 63 | // The stack with "smaller" types is smaller. 64 | { 65 | auto it = a.begin (); 66 | auto jt = b.begin (); 67 | for (; it != a.end (); ++it, ++jt) 68 | if (*it != nullptr && *jt != nullptr) 69 | { 70 | if ((*it)->get_type () < (*jt)->get_type ()) 71 | return -1; 72 | else if ((*jt)->get_type () < (*it)->get_type ()) 73 | return 1; 74 | } 75 | } 76 | 77 | // We have the same number of slots with values of the same type. 78 | // Now compare the values directly. 79 | { 80 | auto it = a.begin (); 81 | auto jt = b.begin (); 82 | for (; it != a.end (); ++it, ++jt) 83 | if (*it != nullptr && *jt != nullptr) 84 | switch ((*it)->cmp (**jt)) 85 | { 86 | case cmp_result::fail: 87 | assert (! "Comparison of same-typed slots shouldn't fail!"); 88 | abort (); 89 | case cmp_result::less: 90 | return -1; 91 | case cmp_result::greater: 92 | return 1; 93 | case cmp_result::equal: 94 | break; 95 | } 96 | } 97 | 98 | // The stacks are the same! 99 | return 0; 100 | } 101 | } 102 | 103 | bool 104 | stack::operator< (stack const &that) const 105 | { 106 | return compare_stack (m_values, that.m_values) < 0; 107 | } 108 | 109 | bool 110 | stack::operator== (stack const &that) const 111 | { 112 | return compare_stack (m_values, that.m_values) == 0; 113 | } 114 | -------------------------------------------------------------------------------- /libzwerg/stack.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017, 2018 Petr Machata 3 | Copyright (C) 2014, 2015 Red Hat, Inc. 4 | This file is part of dwgrep. 5 | 6 | This file is free software; you can redistribute it and/or modify 7 | it under the terms of either 8 | 9 | * the GNU Lesser General Public License as published by the Free 10 | Software Foundation; either version 3 of the License, or (at 11 | your option) any later version 12 | 13 | or 14 | 15 | * the GNU General Public License as published by the Free 16 | Software Foundation; either version 2 of the License, or (at 17 | your option) any later version 18 | 19 | or both in parallel, as here. 20 | 21 | dwgrep is distributed in the hope that it will be useful, but 22 | WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | General Public License for more details. 25 | 26 | You should have received copies of the GNU General Public License and 27 | the GNU Lesser General Public License along with this program. If 28 | not, see . */ 29 | 30 | #ifndef _STK_H_ 31 | #define _STK_H_ 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #include "value.hh" 38 | #include "selector.hh" 39 | 40 | enum var_id: unsigned {}; 41 | 42 | // Stack is a container type that's used for maintaining stacks of dwgrep 43 | // values. 44 | class stack 45 | { 46 | std::vector > m_values; 47 | selector::sel_t m_profile; 48 | 49 | public: 50 | typedef std::unique_ptr uptr; 51 | 52 | stack () 53 | : m_profile {0} 54 | {} 55 | 56 | stack (stack const &other); 57 | stack (stack &&other) = default; 58 | 59 | size_t 60 | size () const 61 | { 62 | return m_values.size (); 63 | } 64 | 65 | selector::sel_t 66 | profile () const 67 | { 68 | return m_profile; 69 | } 70 | 71 | void 72 | push (std::unique_ptr vp) 73 | { 74 | m_profile <<= 8; 75 | m_profile |= vp->get_type ().code (); 76 | m_values.push_back (std::move (vp)); 77 | } 78 | 79 | void 80 | need (unsigned depth) const 81 | { 82 | if (depth > m_values.size ()) 83 | throw std::runtime_error ("stack overflow"); 84 | } 85 | 86 | std::unique_ptr 87 | pop () 88 | { 89 | need (1); 90 | auto ret = std::move (m_values.back ()); 91 | m_values.pop_back (); 92 | m_profile >>= 8; 93 | if (m_values.size () >= selector::W) 94 | { 95 | auto code = get (selector::W - 1).get_type ().code (); 96 | m_profile |= ((selector::sel_t) code) << (8 * (selector::W - 1)); 97 | } 98 | return ret; 99 | } 100 | 101 | void 102 | drop (unsigned n) 103 | { 104 | need (n); 105 | m_values.erase (m_values.end () - n, m_values.end ()); 106 | m_profile = 0; 107 | for (unsigned d = 0; d < selector::W && d < m_values.size (); ++d) 108 | { 109 | auto code = get (d).get_type ().code (); 110 | m_profile |= code << (d * 8); 111 | } 112 | } 113 | 114 | template 115 | std::unique_ptr 116 | pop_as () 117 | { 118 | auto vp = pop (); 119 | assert (vp->is ()); 120 | return std::unique_ptr (static_cast (vp.release ())); 121 | } 122 | 123 | value & 124 | top () 125 | { 126 | need (1); 127 | return *m_values.back ().get (); 128 | } 129 | 130 | value & 131 | get (unsigned depth) 132 | { 133 | need (depth + 1); 134 | return *(m_values.rbegin () + depth)->get (); 135 | } 136 | 137 | value const & 138 | get (unsigned depth) const 139 | { 140 | need (depth + 1); 141 | return *(m_values.rbegin () + depth)->get (); 142 | } 143 | 144 | template 145 | T * 146 | top_as () 147 | { 148 | value const &ret = top (); 149 | return value::as (const_cast (&ret)); 150 | } 151 | 152 | template 153 | T * 154 | get_as (unsigned depth) 155 | { 156 | value const &ret = get (depth); 157 | return value::as (const_cast (&ret)); 158 | } 159 | 160 | bool operator< (stack const &that) const; 161 | bool operator== (stack const &that) const; 162 | }; 163 | 164 | #endif /* _STK_H_ */ 165 | -------------------------------------------------------------------------------- /libzwerg/strip.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #include 30 | #include "strip.hh" 31 | 32 | std::string 33 | strip (std::string const &str, char const *whitespace) 34 | { 35 | std::string::size_type fst = str.find_first_not_of (whitespace, 0); 36 | if (fst == std::string::npos) 37 | return ""; 38 | 39 | auto lst = str.find_last_not_of (whitespace); 40 | assert (lst != std::string::npos); 41 | return str.substr (fst, lst - fst + 1); 42 | } 43 | -------------------------------------------------------------------------------- /libzwerg/strip.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #include 30 | 31 | // Strip whitespace from both ends of STR and return a new one. 32 | std::string strip (std::string const &str, char const *whitespace); 33 | -------------------------------------------------------------------------------- /libzwerg/test-builtin-cmp.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | Copyright (C) 2014 Red Hat, Inc. 4 | This file is part of dwgrep. 5 | 6 | This file is free software; you can redistribute it and/or modify 7 | it under the terms of either 8 | 9 | * the GNU Lesser General Public License as published by the Free 10 | Software Foundation; either version 3 of the License, or (at 11 | your option) any later version 12 | 13 | or 14 | 15 | * the GNU General Public License as published by the Free 16 | Software Foundation; either version 2 of the License, or (at 17 | your option) any later version 18 | 19 | or both in parallel, as here. 20 | 21 | dwgrep is distributed in the hope that it will be useful, but 22 | WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | General Public License for more details. 25 | 26 | You should have received copies of the GNU General Public License and 27 | the GNU Lesser General Public License along with this program. If 28 | not, see . */ 29 | 30 | #include 31 | #include "builtin-cmp.hh" 32 | #include "value-str.hh" 33 | #include "value-cst.hh" 34 | 35 | namespace 36 | { 37 | template 38 | pred_result 39 | result_of_builtin (stack &stk) 40 | { 41 | layout l; 42 | auto pred = Builtin {true}.build_pred (l); 43 | scon sc {l}; 44 | return pred->result (sc, stk); 45 | } 46 | } 47 | 48 | TEST (TestBuiltinCmp, comparison_of_different_types) 49 | { 50 | stack stk; 51 | stk.push (std::make_unique (constant {7, &dec_constant_dom}, 0)); 52 | stk.push (std::make_unique ("foo", 0)); 53 | 54 | auto eqr = result_of_builtin (stk); 55 | auto ltr = result_of_builtin (stk); 56 | auto gtr = result_of_builtin (stk); 57 | 58 | ASSERT_NE (pred_result::fail, eqr); 59 | ASSERT_NE (pred_result::fail, ltr); 60 | ASSERT_NE (pred_result::fail, gtr); 61 | 62 | ASSERT_NE (pred_result::yes, eqr); 63 | ASSERT_TRUE (ltr == pred_result::yes || gtr == pred_result::yes); 64 | ASSERT_FALSE (ltr == pred_result::yes && gtr == pred_result::yes); 65 | } 66 | -------------------------------------------------------------------------------- /libzwerg/test-coverage.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #include 30 | #include "coverage.hh" 31 | 32 | TEST (CoverageTest, format_empty_coverage) 33 | { 34 | coverage cov; 35 | std::string str = cov::format_ranges (cov); 36 | ASSERT_EQ ("[)", str); 37 | } 38 | -------------------------------------------------------------------------------- /libzwerg/test-stub.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #include 30 | #include 31 | 32 | std::string g_test_case_directory; 33 | 34 | struct MinimalistPrinter 35 | : public testing::EmptyTestEventListener 36 | { 37 | void 38 | OnTestPartResult (const testing::TestPartResult& test_part_result) override 39 | { 40 | if (test_part_result.failed ()) 41 | std::cout << "FAIL\t" << test_part_result.file_name () 42 | << ":" << test_part_result.line_number() << std::endl 43 | << test_part_result.summary () << std::endl; 44 | } 45 | }; 46 | 47 | int 48 | main (int argc, char **argv) 49 | { 50 | testing::InitGoogleTest (&argc, argv); 51 | 52 | for (int i = 1; i < argc; ++i) 53 | { 54 | std::string arg = argv[i]; 55 | size_t n = (sizeof "--test-case-directory=") - 1; 56 | if (arg.substr (0, n) == "--test-case-directory=") 57 | g_test_case_directory = arg.substr (n); 58 | } 59 | 60 | assert (g_test_case_directory != ""); 61 | 62 | testing::TestEventListeners& listeners = 63 | testing::UnitTest::GetInstance()->listeners(); 64 | 65 | delete listeners.Release (listeners.default_result_printer ()); 66 | listeners.Append (new MinimalistPrinter); 67 | 68 | return RUN_ALL_TESTS(); 69 | } 70 | -------------------------------------------------------------------------------- /libzwerg/test-value-cst.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014, 2015 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #include 30 | #include "value-cst.hh" 31 | 32 | struct dom 33 | : public constant_dom 34 | { 35 | void show (mpz_class const &c, std::ostream &o, 36 | brevity brv) const override 37 | {} 38 | 39 | char const *name () const override 40 | { return "dom1;"; } 41 | } dom1, dom2; 42 | 43 | TEST (ValueCstTest, comparison_of_different_domains) 44 | { 45 | value_cst cst_a {constant {7, &dom1}, 0}; 46 | value_cst cst_b {constant {7, &dom2}, 0}; 47 | value_cst cst_c {constant {8, &dom1}, 0}; 48 | value_cst cst_d {constant {8, &dom2}, 0}; 49 | 50 | EXPECT_TRUE (cst_a.cmp (cst_b) != cmp_result::equal); 51 | EXPECT_TRUE (cst_a.cmp (cst_b) != cmp_result::fail); 52 | EXPECT_TRUE (cst_b.cmp (cst_a) != cmp_result::equal); 53 | EXPECT_TRUE (cst_b.cmp (cst_a) != cmp_result::fail); 54 | EXPECT_TRUE (cst_a.cmp (cst_b) != cst_b.cmp (cst_a)); 55 | EXPECT_EQ (cst_a.cmp (cst_b), cst_c.cmp (cst_d)); 56 | EXPECT_EQ (cst_b.cmp (cst_a), cst_d.cmp (cst_c)); 57 | } 58 | -------------------------------------------------------------------------------- /libzwerg/test-zw-aux.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | Copyright (C) 2014, 2015 Red Hat, Inc. 4 | This file is part of dwgrep. 5 | 6 | This file is free software; you can redistribute it and/or modify 7 | it under the terms of either 8 | 9 | * the GNU Lesser General Public License as published by the Free 10 | Software Foundation; either version 3 of the License, or (at 11 | your option) any later version 12 | 13 | or 14 | 15 | * the GNU General Public License as published by the Free 16 | Software Foundation; either version 2 of the License, or (at 17 | your option) any later version 18 | 19 | or both in parallel, as here. 20 | 21 | dwgrep is distributed in the hope that it will be useful, but 22 | WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | General Public License for more details. 25 | 26 | You should have received copies of the GNU General Public License and 27 | the GNU Lesser General Public License along with this program. If 28 | not, see . */ 29 | 30 | #include "test-zw-aux.hh" 31 | #include "op.hh" 32 | #include "parser.hh" 33 | #include "scon.hh" 34 | 35 | 36 | std::unique_ptr 37 | stack_with_value (std::unique_ptr v) 38 | { 39 | auto stk = std::make_unique (); 40 | stk->push (std::move (v)); 41 | return stk; 42 | } 43 | 44 | std::vector > 45 | run_query (vocabulary &voc, 46 | std::unique_ptr stk, std::string q) 47 | { 48 | layout l; 49 | auto origin = std::make_shared (l); 50 | auto op = parse_query (q).build_exec (l, origin, voc); 51 | 52 | scon sc {l}; 53 | scon_guard sg {sc, *op}; 54 | origin->set_next (sc, std::move (stk)); 55 | 56 | std::vector > yielded; 57 | while (auto r = op->next (sc)) 58 | yielded.push_back (std::move (r)); 59 | 60 | return yielded; 61 | } 62 | 63 | std::string 64 | get_parse_error (vocabulary &voc, std::string q) 65 | { 66 | layout l; 67 | auto origin = std::make_shared (l); 68 | try 69 | { 70 | parse_query (q).build_exec (l, origin, voc); 71 | } 72 | catch (std::runtime_error &err) 73 | { 74 | return err.what (); 75 | } 76 | catch (...) 77 | { 78 | return "???"; 79 | } 80 | 81 | return ""; 82 | } 83 | -------------------------------------------------------------------------------- /libzwerg/test-zw-aux.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | Copyright (C) 2014, 2015 Red Hat, Inc. 4 | This file is part of dwgrep. 5 | 6 | This file is free software; you can redistribute it and/or modify 7 | it under the terms of either 8 | 9 | * the GNU Lesser General Public License as published by the Free 10 | Software Foundation; either version 3 of the License, or (at 11 | your option) any later version 12 | 13 | or 14 | 15 | * the GNU General Public License as published by the Free 16 | Software Foundation; either version 2 of the License, or (at 17 | your option) any later version 18 | 19 | or both in parallel, as here. 20 | 21 | dwgrep is distributed in the hope that it will be useful, but 22 | WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | General Public License for more details. 25 | 26 | You should have received copies of the GNU General Public License and 27 | the GNU Lesser General Public License along with this program. If 28 | not, see . */ 29 | 30 | #ifndef TEST_ZW_AUX_H 31 | #define TEST_ZW_AUX_H 32 | 33 | #include 34 | 35 | #include "stack.hh" 36 | #include "value.hh" 37 | #include "builtin.hh" 38 | 39 | std::unique_ptr stack_with_value (std::unique_ptr v); 40 | 41 | std::vector > 42 | run_query (vocabulary &voc, std::unique_ptr stk, std::string q); 43 | 44 | std::string get_parse_error (vocabulary &voc, std::string q); 45 | 46 | #endif /* TEST_ZW_AUX_H */ 47 | -------------------------------------------------------------------------------- /libzwerg/tree_cr.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | Copyright (C) 2014 Red Hat, Inc. 4 | This file is part of dwgrep. 5 | 6 | This file is free software; you can redistribute it and/or modify 7 | it under the terms of either 8 | 9 | * the GNU Lesser General Public License as published by the Free 10 | Software Foundation; either version 3 of the License, or (at 11 | your option) any later version 12 | 13 | or 14 | 15 | * the GNU General Public License as published by the Free 16 | Software Foundation; either version 2 of the License, or (at 17 | your option) any later version 18 | 19 | or both in parallel, as here. 20 | 21 | dwgrep is distributed in the hope that it will be useful, but 22 | WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | General Public License for more details. 25 | 26 | You should have received copies of the GNU General Public License and 27 | the GNU Lesser General Public License along with this program. If 28 | not, see . */ 29 | 30 | #include "tree_cr.hh" 31 | 32 | std::unique_ptr 33 | tree::create_builtin (std::shared_ptr b) 34 | { 35 | auto t = std::make_unique (tree_type::F_BUILTIN); 36 | t->m_builtin = b; 37 | return t; 38 | } 39 | 40 | std::unique_ptr 41 | tree::create_neg (std::unique_ptr t) 42 | { 43 | return tree::create_unary (std::move (t)); 44 | } 45 | 46 | std::unique_ptr 47 | tree::create_assert (std::unique_ptr t) 48 | { 49 | return tree::create_unary (std::move (t)); 50 | } 51 | 52 | std::unique_ptr 53 | tree::create_scope (std::unique_ptr t1) 54 | { 55 | auto t = std::make_unique (tree_type::SCOPE); 56 | t->take_child (std::move (t1)); 57 | return t; 58 | } 59 | 60 | void 61 | tree::take_child (std::unique_ptr t) 62 | { 63 | m_children.push_back (*t); 64 | } 65 | 66 | void 67 | tree::take_child_front (std::unique_ptr t) 68 | { 69 | m_children.insert (m_children.begin (), *t); 70 | } 71 | 72 | void 73 | tree::take_cat (std::unique_ptr t) 74 | { 75 | m_children.insert (m_children.end (), 76 | t->m_children.begin (), t->m_children.end ()); 77 | } 78 | -------------------------------------------------------------------------------- /libzwerg/tree_cr.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #ifndef _TREE_CR_H_ 30 | #define _TREE_CR_H_ 31 | 32 | #include "tree.hh" 33 | 34 | template 35 | std::unique_ptr 36 | tree::create_nullary () 37 | { 38 | static_assert (tree_arity ::value == tree_arity_v::NULLARY, 39 | "Wrong tree arity."); 40 | return std::make_unique (TT); 41 | } 42 | 43 | template 44 | std::unique_ptr 45 | tree::create_unary (std::unique_ptr op) 46 | { 47 | static_assert (tree_arity ::value == tree_arity_v::UNARY, 48 | "Wrong tree arity."); 49 | auto t = std::make_unique (TT); 50 | t->take_child (std::move (op)); 51 | return t; 52 | } 53 | 54 | template 55 | std::unique_ptr 56 | tree::create_binary (std::unique_ptr lhs, std::unique_ptr rhs) 57 | { 58 | static_assert (tree_arity ::value == tree_arity_v::BINARY, 59 | "Wrong tree arity."); 60 | auto t = std::make_unique (TT); 61 | t->take_child (std::move (lhs)); 62 | t->take_child (std::move (rhs)); 63 | return t; 64 | } 65 | 66 | template 67 | std::unique_ptr 68 | tree::create_ternary (std::unique_ptr op1, std::unique_ptr op2, 69 | std::unique_ptr op3) 70 | { 71 | static_assert (tree_arity ::value == tree_arity_v::TERNARY, 72 | "Wrong tree arity."); 73 | auto t = std::make_unique (TT); 74 | t->take_child (std::move (op1)); 75 | t->take_child (std::move (op2)); 76 | t->take_child (std::move (op3)); 77 | return t; 78 | } 79 | 80 | template 81 | std::unique_ptr 82 | tree::create_str (std::string s) 83 | { 84 | static_assert (tree_arity ::value == tree_arity_v::STR, 85 | "Wrong tree arity."); 86 | auto t = std::make_unique (TT); 87 | t->m_str = std::make_unique (std::move (s)); 88 | return t; 89 | } 90 | 91 | template 92 | std::unique_ptr 93 | tree::create_const (constant c) 94 | { 95 | static_assert (tree_arity ::value == tree_arity_v::CST, 96 | "Wrong tree arity."); 97 | auto t = std::make_unique (TT); 98 | t->m_cst = std::make_unique (std::move (c)); 99 | return t; 100 | } 101 | 102 | // Creates either a CAT or an ALT node. 103 | // 104 | // It is smart in that it transforms CAT's of CAT's into one 105 | // overarching CAT, and appends or prepends other nodes to an 106 | // existing CAT if possible. It also knows to ignore a nullptr 107 | // tree. 108 | template 109 | std::unique_ptr 110 | tree::create_cat (std::unique_ptr t1, std::unique_ptr t2) 111 | { 112 | bool cat1 = t1 != nullptr && t1->m_tt == TT; 113 | bool cat2 = t2 != nullptr && t2->m_tt == TT; 114 | 115 | if (cat1 && cat2) 116 | { 117 | t1->take_cat (std::move (t2)); 118 | return t1; 119 | } 120 | else if (cat1 && t2 != nullptr) 121 | { 122 | t1->take_child (std::move (t2)); 123 | return t1; 124 | } 125 | else if (cat2 && t1 != nullptr) 126 | { 127 | t2->take_child_front (std::move (t1)); 128 | return t2; 129 | } 130 | 131 | if (t1 == nullptr) 132 | { 133 | assert (t2 != nullptr); 134 | return t2; 135 | } 136 | else if (t2 == nullptr) 137 | return t1; 138 | else 139 | return tree::create_binary (std::move (t1), std::move (t2)); 140 | } 141 | 142 | #endif /* _TREE_CR_H_ */ 143 | -------------------------------------------------------------------------------- /libzwerg/value-aset.cc: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of dwgrep. 3 | 4 | This file is free software; you can redistribute it and/or modify 5 | it under the terms of either 6 | 7 | * the GNU Lesser General Public License as published by the Free 8 | Software Foundation; either version 3 of the License, or (at 9 | your option) any later version 10 | 11 | or 12 | 13 | * the GNU General Public License as published by the Free 14 | Software Foundation; either version 2 of the License, or (at 15 | your option) any later version 16 | 17 | or both in parallel, as here. 18 | 19 | dwgrep is distributed in the hope that it will be useful, but 20 | WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | General Public License for more details. 23 | 24 | You should have received copies of the GNU General Public License and 25 | the GNU Lesser General Public License along with this program. If 26 | not, see . */ 27 | 28 | #include "value-aset.hh" 29 | 30 | value_type const value_aset::vtype = value_type::alloc ("T_ASET", 31 | R"docstring( 32 | 33 | Values of this type contain sets of addresses. They are used for 34 | representing address ranges of all sorts. They behave a bit like 35 | sequences of constants, but calling ``elem`` is not advised unless you 36 | can be sure that the address range is not excessively large:: 37 | 38 | $ dwgrep ./tests/bitcount.o -e 'entry @AT_location address' 39 | [0x10000, 0x10017) 40 | [0x10017, 0x1001a) 41 | [0x1001a, 0x10020) 42 | [0x10000, 0x10007) 43 | [0x10007, 0x1001e) 44 | [0x1001e, 0x10020) 45 | 46 | Address sets don't have to be continuous. 47 | 48 | )docstring"); 49 | 50 | void 51 | value_aset::show (std::ostream &o) const 52 | { 53 | o << cov::format_ranges {cov}; 54 | } 55 | 56 | std::unique_ptr 57 | value_aset::clone () const 58 | { 59 | return std::make_unique (*this); 60 | } 61 | 62 | cmp_result 63 | value_aset::cmp (value const &that) const 64 | { 65 | if (auto v = value::as (&that)) 66 | { 67 | auto const &cov2 = v->cov; 68 | 69 | cmp_result ret = compare (cov.size (), cov2.size ()); 70 | if (ret != cmp_result::equal) 71 | return ret; 72 | 73 | for (size_t i = 0; i < cov.size (); ++i) 74 | if ((ret = compare (cov.at (i).start, 75 | cov2.at (i).start)) != cmp_result::equal) 76 | return ret; 77 | else if ((ret = compare (cov.at (i).length, 78 | cov2.at (i).length)) != cmp_result::equal) 79 | return ret; 80 | 81 | return cmp_result::equal; 82 | } 83 | else 84 | return cmp_result::fail; 85 | } 86 | -------------------------------------------------------------------------------- /libzwerg/value-aset.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2015 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #ifndef VALUE_ASET_H 30 | #define VALUE_ASET_H 31 | 32 | #include 33 | #include "coverage.hh" 34 | #include "value.hh" 35 | 36 | // Set of addresses. 37 | struct value_aset 38 | : public value 39 | { 40 | coverage cov; 41 | 42 | static value_type const vtype; 43 | 44 | value_aset (coverage a_cov, size_t pos) 45 | : value {vtype, pos} 46 | , cov {std::move (a_cov)} 47 | {} 48 | 49 | value_aset (value_aset const &that) = default; 50 | 51 | coverage &get_coverage () 52 | { return cov; } 53 | 54 | coverage const &get_coverage () const 55 | { return cov; } 56 | 57 | void show (std::ostream &o) const override; 58 | std::unique_ptr clone () const override; 59 | cmp_result cmp (value const &that) const override; 60 | }; 61 | 62 | #endif /* VALUE_ASET_H */ 63 | -------------------------------------------------------------------------------- /libzwerg/value-closure.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | Copyright (C) 2014, 2015 Red Hat, Inc. 4 | This file is part of dwgrep. 5 | 6 | This file is free software; you can redistribute it and/or modify 7 | it under the terms of either 8 | 9 | * the GNU Lesser General Public License as published by the Free 10 | Software Foundation; either version 3 of the License, or (at 11 | your option) any later version 12 | 13 | or 14 | 15 | * the GNU General Public License as published by the Free 16 | Software Foundation; either version 2 of the License, or (at 17 | your option) any later version 18 | 19 | or both in parallel, as here. 20 | 21 | dwgrep is distributed in the hope that it will be useful, but 22 | WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | General Public License for more details. 25 | 26 | You should have received copies of the GNU General Public License and 27 | the GNU Lesser General Public License along with this program. If 28 | not, see . */ 29 | 30 | #include 31 | #include 32 | 33 | #include "value-closure.hh" 34 | #include "tree.hh" 35 | 36 | value_type const value_closure::vtype 37 | = value_type::alloc ("T_CLOSURE", "@hide"); 38 | 39 | value_closure::value_closure (layout op_layout, layout::loc rdv_ll, 40 | std::shared_ptr origin, 41 | std::shared_ptr op, 42 | std::vector > env, 43 | size_t pos) 44 | : value {vtype, pos} 45 | , m_op_layout {op_layout} 46 | , m_rdv_ll {rdv_ll} 47 | , m_origin {origin} 48 | , m_op {op} 49 | , m_env {std::move (env)} 50 | {} 51 | 52 | void 53 | value_closure::show (std::ostream &o) const 54 | { 55 | o << "closure"; 56 | } 57 | 58 | std::unique_ptr 59 | value_closure::clone () const 60 | { 61 | std::vector > env; 62 | for (auto const &envv: m_env) 63 | env.push_back (envv->clone ()); 64 | return std::make_unique (m_op_layout, m_rdv_ll, 65 | m_origin, m_op, 66 | std::move (env), get_pos ()); 67 | } 68 | 69 | cmp_result 70 | value_closure::cmp (value const &v) const 71 | { 72 | if (auto that = value::as (&v)) 73 | { 74 | auto a = std::make_tuple (m_op, std::cref (m_env)); 75 | auto b = std::make_tuple (that->m_op, std::cref (that->m_env)); 76 | return compare (a, b); 77 | } 78 | else 79 | return cmp_result::fail; 80 | } 81 | -------------------------------------------------------------------------------- /libzwerg/value-closure.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | Copyright (C) 2014, 2015 Red Hat, Inc. 4 | This file is part of dwgrep. 5 | 6 | This file is free software; you can redistribute it and/or modify 7 | it under the terms of either 8 | 9 | * the GNU Lesser General Public License as published by the Free 10 | Software Foundation; either version 3 of the License, or (at 11 | your option) any later version 12 | 13 | or 14 | 15 | * the GNU General Public License as published by the Free 16 | Software Foundation; either version 2 of the License, or (at 17 | your option) any later version 18 | 19 | or both in parallel, as here. 20 | 21 | dwgrep is distributed in the hope that it will be useful, but 22 | WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | General Public License for more details. 25 | 26 | You should have received copies of the GNU General Public License and 27 | the GNU Lesser General Public License along with this program. If 28 | not, see . */ 29 | 30 | #ifndef _VALUE_CLOSURE_H_ 31 | #define _VALUE_CLOSURE_H_ 32 | 33 | #include "op.hh" 34 | #include "value.hh" 35 | #include "layout.hh" 36 | 37 | class value_closure 38 | : public value 39 | { 40 | layout m_op_layout; 41 | layout::loc m_rdv_ll; 42 | std::shared_ptr m_origin; 43 | std::shared_ptr m_op; 44 | std::vector > m_env; 45 | 46 | public: 47 | static value_type const vtype; 48 | 49 | value_closure (layout op_layout, layout::loc rdv_ll, 50 | std::shared_ptr origin, 51 | std::shared_ptr op, 52 | std::vector > env, 53 | size_t pos); 54 | 55 | void show (std::ostream &o) const override; 56 | std::unique_ptr clone () const override; 57 | cmp_result cmp (value const &that) const override; 58 | 59 | layout const &get_layout () const 60 | { return m_op_layout; } 61 | 62 | op_origin &get_origin () const 63 | { return *m_origin; } 64 | 65 | op &get_op () const 66 | { return *m_op; } 67 | 68 | value &get_env (unsigned id) 69 | { return *m_env[id]; } 70 | 71 | layout::loc get_rdv_ll () const 72 | { return m_rdv_ll; } 73 | }; 74 | 75 | #endif /* _VALUE_CLOSURE_H_ */ 76 | -------------------------------------------------------------------------------- /libzwerg/value-cst.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | Copyright (C) 2014, 2015 Red Hat, Inc. 4 | This file is part of dwgrep. 5 | 6 | This file is free software; you can redistribute it and/or modify 7 | it under the terms of either 8 | 9 | * the GNU Lesser General Public License as published by the Free 10 | Software Foundation; either version 3 of the License, or (at 11 | your option) any later version 12 | 13 | or 14 | 15 | * the GNU General Public License as published by the Free 16 | Software Foundation; either version 2 of the License, or (at 17 | your option) any later version 18 | 19 | or both in parallel, as here. 20 | 21 | dwgrep is distributed in the hope that it will be useful, but 22 | WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | General Public License for more details. 25 | 26 | You should have received copies of the GNU General Public License and 27 | the GNU Lesser General Public License along with this program. If 28 | not, see . */ 29 | 30 | #ifndef _VALUE_CST_H_ 31 | #define _VALUE_CST_H_ 32 | 33 | #include "value.hh" 34 | #include "op.hh" 35 | #include "overload.hh" 36 | 37 | class value_cst 38 | : public value 39 | { 40 | constant m_cst; 41 | 42 | public: 43 | static value_type const vtype; 44 | 45 | value_cst (constant cst, size_t pos) 46 | : value {vtype, pos} 47 | , m_cst {cst} 48 | {} 49 | 50 | value_cst (value_cst const &that) = default; 51 | 52 | constant const &get_constant () const 53 | { return m_cst; } 54 | 55 | void show (std::ostream &o) const override; 56 | std::unique_ptr clone () const override; 57 | cmp_result cmp (value const &that) const override; 58 | }; 59 | 60 | struct op_value_cst 61 | : public op_once_overload 62 | { 63 | using op_once_overload::op_once_overload; 64 | 65 | value_cst operate (std::unique_ptr a) const override; 66 | 67 | static std::string docstring (); 68 | }; 69 | 70 | 71 | // Arithmetic operator overloads. 72 | 73 | struct op_add_cst 74 | : public op_overload 75 | { 76 | using op_overload::op_overload; 77 | 78 | std::unique_ptr 79 | operate (std::unique_ptr a, 80 | std::unique_ptr b) const override; 81 | static std::string docstring (); 82 | }; 83 | 84 | struct op_sub_cst 85 | : public op_overload 86 | { 87 | using op_overload::op_overload; 88 | 89 | std::unique_ptr 90 | operate (std::unique_ptr a, 91 | std::unique_ptr b) const override; 92 | static std::string docstring (); 93 | }; 94 | 95 | struct op_mul_cst 96 | : public op_overload 97 | { 98 | using op_overload::op_overload; 99 | 100 | std::unique_ptr 101 | operate (std::unique_ptr a, 102 | std::unique_ptr b) const override; 103 | static std::string docstring (); 104 | }; 105 | 106 | struct op_div_cst 107 | : public op_overload 108 | { 109 | using op_overload::op_overload; 110 | 111 | std::unique_ptr 112 | operate (std::unique_ptr a, 113 | std::unique_ptr b) const override; 114 | static std::string docstring (); 115 | }; 116 | 117 | struct op_mod_cst 118 | : public op_overload 119 | { 120 | using op_overload::op_overload; 121 | 122 | std::unique_ptr 123 | operate (std::unique_ptr a, 124 | std::unique_ptr b) const override; 125 | static std::string docstring (); 126 | }; 127 | 128 | #endif /* _VALUE_CST_H_ */ 129 | -------------------------------------------------------------------------------- /libzwerg/value-seq.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | Copyright (C) 2014, 2015 Red Hat, Inc. 4 | This file is part of dwgrep. 5 | 6 | This file is free software; you can redistribute it and/or modify 7 | it under the terms of either 8 | 9 | * the GNU Lesser General Public License as published by the Free 10 | Software Foundation; either version 3 of the License, or (at 11 | your option) any later version 12 | 13 | or 14 | 15 | * the GNU General Public License as published by the Free 16 | Software Foundation; either version 2 of the License, or (at 17 | your option) any later version 18 | 19 | or both in parallel, as here. 20 | 21 | dwgrep is distributed in the hope that it will be useful, but 22 | WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | General Public License for more details. 25 | 26 | You should have received copies of the GNU General Public License and 27 | the GNU Lesser General Public License along with this program. If 28 | not, see . */ 29 | 30 | #ifndef _VALUE_SEQ_H_ 31 | #define _VALUE_SEQ_H_ 32 | 33 | #include "value.hh" 34 | #include "op.hh" 35 | #include "overload.hh" 36 | #include "value-cst.hh" 37 | 38 | class value_seq 39 | : public value 40 | { 41 | public: 42 | typedef std::vector > seq_t; 43 | 44 | private: 45 | std::shared_ptr m_seq; 46 | 47 | public: 48 | static value_type const vtype; 49 | 50 | value_seq (seq_t &&seq, size_t pos) 51 | : value {vtype, pos} 52 | , m_seq {std::make_shared (std::move (seq))} 53 | {} 54 | 55 | value_seq (std::shared_ptr seqp, size_t pos) 56 | : value {vtype, pos} 57 | , m_seq {seqp} 58 | {} 59 | 60 | value_seq (value_seq const &that); 61 | 62 | std::shared_ptr 63 | get_seq () const 64 | { 65 | return m_seq; 66 | } 67 | 68 | void show (std::ostream &o) const override; 69 | std::unique_ptr clone () const override; 70 | cmp_result cmp (value const &that) const override; 71 | }; 72 | 73 | struct op_add_seq 74 | : public op_once_overload 75 | { 76 | using op_once_overload::op_once_overload; 77 | 78 | value_seq operate (std::unique_ptr a, 79 | std::unique_ptr b) const override; 80 | 81 | static std::string docstring (); 82 | }; 83 | 84 | struct op_length_seq 85 | : public op_once_overload 86 | { 87 | using op_once_overload::op_once_overload; 88 | 89 | value_cst operate (std::unique_ptr a) const override; 90 | 91 | static std::string docstring (); 92 | }; 93 | 94 | struct op_elem_seq 95 | : public op_yielding_overload 96 | { 97 | using op_yielding_overload::op_yielding_overload; 98 | 99 | std::unique_ptr > 100 | operate (std::unique_ptr a) const override; 101 | 102 | static std::string docstring (); 103 | }; 104 | 105 | struct op_relem_seq 106 | : public op_yielding_overload 107 | { 108 | using op_yielding_overload::op_yielding_overload; 109 | 110 | std::unique_ptr > 111 | operate (std::unique_ptr a) const override; 112 | 113 | static std::string docstring (); 114 | }; 115 | 116 | struct pred_empty_seq 117 | : public pred_overload 118 | { 119 | using pred_overload::pred_overload; 120 | pred_result result (value_seq &a) const override; 121 | 122 | static std::string docstring (); 123 | }; 124 | 125 | struct pred_find_seq 126 | : public pred_overload 127 | { 128 | using pred_overload::pred_overload; 129 | pred_result result (value_seq &haystack, value_seq &needle) const override; 130 | 131 | static std::string docstring (); 132 | }; 133 | 134 | struct pred_starts_seq 135 | : public pred_overload 136 | { 137 | using pred_overload::pred_overload; 138 | pred_result result (value_seq &haystack, value_seq &needle) const override; 139 | 140 | static std::string docstring (); 141 | }; 142 | 143 | struct pred_ends_seq 144 | : public pred_overload 145 | { 146 | using pred_overload::pred_overload; 147 | pred_result result (value_seq &haystack, value_seq &needle) const override; 148 | 149 | static std::string docstring (); 150 | }; 151 | 152 | #endif /* _VALUE_SEQ_H_ */ 153 | -------------------------------------------------------------------------------- /libzwerg/value-str.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 Petr Machata 3 | Copyright (C) 2014, 2015 Red Hat, Inc. 4 | This file is part of dwgrep. 5 | 6 | This file is free software; you can redistribute it and/or modify 7 | it under the terms of either 8 | 9 | * the GNU Lesser General Public License as published by the Free 10 | Software Foundation; either version 3 of the License, or (at 11 | your option) any later version 12 | 13 | or 14 | 15 | * the GNU General Public License as published by the Free 16 | Software Foundation; either version 2 of the License, or (at 17 | your option) any later version 18 | 19 | or both in parallel, as here. 20 | 21 | dwgrep is distributed in the hope that it will be useful, but 22 | WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | General Public License for more details. 25 | 26 | You should have received copies of the GNU General Public License and 27 | the GNU Lesser General Public License along with this program. If 28 | not, see . */ 29 | 30 | #ifndef _VALUE_STR_H_ 31 | #define _VALUE_STR_H_ 32 | 33 | #include 34 | 35 | #include "value.hh" 36 | #include "op.hh" 37 | #include "overload.hh" 38 | #include "value-cst.hh" 39 | 40 | class value_str 41 | : public value 42 | { 43 | std::string m_str; 44 | 45 | public: 46 | static value_type const vtype; 47 | 48 | value_str (std::string str, size_t pos) 49 | : value {vtype, pos} 50 | , m_str {std::move (str)} 51 | {} 52 | 53 | std::string &get_string () 54 | { return m_str; } 55 | 56 | std::string const &get_string () const 57 | { return m_str; } 58 | 59 | void show (std::ostream &o) const override; 60 | std::unique_ptr clone () const override; 61 | cmp_result cmp (value const &that) const override; 62 | }; 63 | 64 | struct op_add_str 65 | : public op_once_overload 66 | { 67 | using op_once_overload::op_once_overload; 68 | 69 | value_str operate (std::unique_ptr a, 70 | std::unique_ptr b) const override; 71 | 72 | static std::string docstring (); 73 | }; 74 | 75 | struct op_length_str 76 | : public op_once_overload 77 | { 78 | using op_once_overload::op_once_overload; 79 | 80 | value_cst operate (std::unique_ptr a) const override; 81 | 82 | static std::string docstring (); 83 | }; 84 | 85 | struct op_elem_str 86 | : public op_yielding_overload 87 | { 88 | using op_yielding_overload::op_yielding_overload; 89 | 90 | std::unique_ptr > 91 | operate (std::unique_ptr a) const override; 92 | 93 | static std::string docstring (); 94 | }; 95 | 96 | struct op_relem_str 97 | : public op_yielding_overload 98 | { 99 | using op_yielding_overload::op_yielding_overload; 100 | 101 | std::unique_ptr > 102 | operate (std::unique_ptr a) const override; 103 | 104 | static std::string docstring (); 105 | }; 106 | 107 | struct pred_empty_str 108 | : public pred_overload 109 | { 110 | using pred_overload::pred_overload; 111 | pred_result result (value_str &a) const override; 112 | 113 | static std::string docstring (); 114 | }; 115 | 116 | struct pred_find_str 117 | : public pred_overload 118 | { 119 | using pred_overload::pred_overload; 120 | pred_result result (value_str &haystack, value_str &needle) const override; 121 | 122 | static std::string docstring (); 123 | }; 124 | 125 | struct pred_starts_str 126 | : public pred_overload 127 | { 128 | using pred_overload::pred_overload; 129 | pred_result result (value_str &haystack, value_str &needle) const override; 130 | 131 | static std::string docstring (); 132 | }; 133 | 134 | struct pred_ends_str 135 | : public pred_overload 136 | { 137 | using pred_overload::pred_overload; 138 | pred_result result (value_str &haystack, value_str &needle) const override; 139 | 140 | static std::string docstring (); 141 | }; 142 | 143 | struct pred_match_str 144 | : public pred_overload 145 | { 146 | using pred_overload::pred_overload; 147 | pred_result result (value_str &haystack, value_str &needle) const override; 148 | 149 | static std::string docstring (); 150 | }; 151 | 152 | #endif /* _VALUE_STR_H_ */ 153 | -------------------------------------------------------------------------------- /libzwerg/value-symbol.hh: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014, 2015 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #ifndef BUILTIN_SYMBOL_H 30 | #define BUILTIN_SYMBOL_H 31 | 32 | #include 33 | 34 | #include "value.hh" 35 | #include "dwfl_context.hh" 36 | #include "value-dw.hh" 37 | 38 | class value_symbol 39 | : public value 40 | , public doneness_aspect 41 | { 42 | std::shared_ptr m_dwctx; 43 | GElf_Sym m_symbol; 44 | char const *m_name; 45 | dwarf_value_cache m_dwcache; 46 | unsigned m_symidx; 47 | 48 | public: 49 | static value_type const vtype; 50 | 51 | value_symbol (std::shared_ptr dwctx, GElf_Sym symbol, 52 | char const *name, unsigned symidx, size_t pos, doneness d) 53 | : value {vtype, pos} 54 | , doneness_aspect {d} 55 | , m_dwctx {dwctx} 56 | , m_symbol (symbol) 57 | , m_name {name} 58 | , m_symidx {symidx} 59 | {} 60 | 61 | std::shared_ptr get_dwctx () const 62 | { return m_dwctx; } 63 | 64 | char const *get_name () const 65 | { return m_name; } 66 | 67 | GElf_Sym get_symbol () const 68 | { return m_symbol; } 69 | 70 | unsigned get_symidx () const 71 | { return m_symidx; } 72 | 73 | void show (std::ostream &o) const override; 74 | std::unique_ptr clone () const override; 75 | cmp_result cmp (value const &that) const override; 76 | 77 | value_dwarf & 78 | get_dwarf () 79 | { 80 | return m_dwcache.get_dwarf (m_dwctx, 0, get_doneness ()); 81 | } 82 | 83 | constant get_type () const; 84 | constant get_address () const; 85 | }; 86 | 87 | constant_dom const &elfsym_stt_dom (int machine); 88 | constant_dom const &elfsym_stb_dom (int machine); 89 | constant_dom const &elfsym_stv_dom (); 90 | 91 | #endif /* BUILTIN_SYMBOL_H */ 92 | -------------------------------------------------------------------------------- /libzwerg/value.cc: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014, 2015 Red Hat, Inc. 3 | This file is part of dwgrep. 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either 7 | 8 | * the GNU Lesser General Public License as published by the Free 9 | Software Foundation; either version 3 of the License, or (at 10 | your option) any later version 11 | 12 | or 13 | 14 | * the GNU General Public License as published by the Free 15 | Software Foundation; either version 2 of the License, or (at 16 | your option) any later version 17 | 18 | or both in parallel, as here. 19 | 20 | dwgrep is distributed in the hope that it will be useful, but 21 | WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | General Public License for more details. 24 | 25 | You should have received copies of the GNU General Public License and 26 | the GNU Lesser General Public License along with this program. If 27 | not, see . */ 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include "op.hh" 34 | #include "tree.hh" 35 | #include "value.hh" 36 | 37 | std::ostream & 38 | operator<< (std::ostream &o, cmp_result result) 39 | { 40 | switch (result) 41 | { 42 | case cmp_result::less: 43 | return o << "less"; 44 | case cmp_result::equal: 45 | return o << "equal"; 46 | case cmp_result::greater: 47 | return o << "greater"; 48 | case cmp_result::fail: 49 | return o << "fail"; 50 | } 51 | return o; 52 | } 53 | 54 | value_type 55 | value_type::alloc (char const *name, char const *docstring) 56 | { 57 | static uint8_t last = 0; 58 | value_type vt {++last, name, docstring}; 59 | if (last == 0) 60 | { 61 | std::cerr << "Ran out of value type identifiers." << std::endl; 62 | std::terminate (); 63 | } 64 | return vt; 65 | } 66 | 67 | value_type const value::vtype = value_type::alloc ("T_???"); 68 | 69 | namespace 70 | { 71 | std::vector > & 72 | get_vtype_names () 73 | { 74 | static std::vector > names; 75 | return names; 76 | } 77 | 78 | std::vector > & 79 | get_vtype_docstrings () 80 | { 81 | static std::vector > docstrings; 82 | return docstrings; 83 | } 84 | 85 | char const * 86 | find_vtype_name (uint8_t code) 87 | { 88 | auto &vtn = get_vtype_names (); 89 | auto it = std::find_if (vtn.begin (), vtn.end (), 90 | [code] (std::pair const &v) 91 | { return v.first == code; }); 92 | if (it == vtn.end ()) 93 | return nullptr; 94 | else 95 | return it->second; 96 | } 97 | } 98 | 99 | void 100 | value_type::register_type (uint8_t code, 101 | char const *name, char const *docstring) 102 | { 103 | auto &vtn = get_vtype_names (); 104 | assert (find_vtype_name (code) == nullptr); 105 | vtn.push_back (std::make_pair (code, name)); 106 | get_vtype_docstrings ().push_back (std::make_pair (code, docstring)); 107 | } 108 | 109 | char const * 110 | value_type::name () const 111 | { 112 | auto ret = find_vtype_name (m_code); 113 | assert (ret != nullptr); 114 | return ret; 115 | } 116 | 117 | std::vector > 118 | value_type::get_docstrings () 119 | { 120 | return get_vtype_docstrings (); 121 | } 122 | 123 | std::vector > 124 | value_type::get_names () 125 | { 126 | return get_vtype_names (); 127 | } 128 | 129 | std::ostream & 130 | operator<< (std::ostream &o, value_type const &v) 131 | { 132 | return o << v.name (); 133 | } 134 | 135 | static struct 136 | : public constant_dom 137 | { 138 | void 139 | show (mpz_class const &v, std::ostream &o, brevity brv) const override 140 | { 141 | assert (v >= 0); 142 | 143 | uint64_t ui = v.uval (); 144 | static_assert (sizeof (value_type) == 1, 145 | "assuming value_type is 8 bits large"); 146 | if (ui <= 0xff) 147 | { 148 | char const *name = find_vtype_name (ui); 149 | assert (name != nullptr); 150 | assert (name[0] == 'T' && name[1] == '_'); 151 | o << (&name[brv == brevity::full ? 0 : 2]); 152 | return; 153 | } 154 | 155 | assert (! "Invalid slot type constant value."); 156 | abort (); 157 | } 158 | 159 | char const *name () const override 160 | { 161 | return "T_*"; 162 | } 163 | } slot_type_dom_obj; 164 | 165 | constant_dom const &slot_type_dom = slot_type_dom_obj; 166 | 167 | constant 168 | value::get_type_const () const 169 | { 170 | return {get_type ().code (), &slot_type_dom}; 171 | } 172 | 173 | std::ostream & 174 | operator<< (std::ostream &o, value const &v) 175 | { 176 | v.show (o); 177 | return o; 178 | } 179 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_TEST (RegressionTests 2 | ${CMAKE_SOURCE_DIR}/tests/tests.sh 3 | ${CMAKE_CURRENT_BINARY_DIR}/../dwgrep/dwgrep) 4 | -------------------------------------------------------------------------------- /tests/a-common.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/a-common.out -------------------------------------------------------------------------------- /tests/a1.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/a1.out -------------------------------------------------------------------------------- /tests/aranges.c: -------------------------------------------------------------------------------- 1 | void *foo (void *, void *); 2 | 3 | void bar (void *ptr) { 4 | ({ 5 | void *_ptr = foo (0, &ptr); 6 | _ptr != 0; 7 | }); 8 | } 9 | -------------------------------------------------------------------------------- /tests/aranges.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/aranges.o -------------------------------------------------------------------------------- /tests/attribute-die-cooked-no-dup.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/attribute-die-cooked-no-dup.o -------------------------------------------------------------------------------- /tests/attribute-die-cooked-no-dup.tcl: -------------------------------------------------------------------------------- 1 | # This test case uses dwarf.exp from GDB. 2 | # GDB_SRCPATH=/path/to/gdb/source tclsh attribute-die-cooked-no-dup.tcl 3 | # gcc -c attribute-die-cooked-no-dup.s 4 | 5 | source "dwarf.exp" 6 | 7 | Dwarf::assemble "attribute-die-cooked-no-dup.s" { 8 | build_id 0102030405060708 9 | 10 | cu {is_64 0 version 4 addr_size 8} { 11 | declare_labels a b c d 12 | 13 | compile_unit {} { 14 | a: subprogram {} 15 | b: subprogram { 16 | {specification :$a} 17 | } 18 | c: subprogram { 19 | {specification :$b} 20 | } 21 | d: subprogram { 22 | {abstract_origin :$c} 23 | } 24 | GNU_call_site { 25 | {abstract_origin :$d} 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/bitcount.c: -------------------------------------------------------------------------------- 1 | #include 2 | unsigned 3 | bitcount(uint64_t u) 4 | { 5 | int c = 0; 6 | for (; u > 0; u &= u - 1) 7 | c++; 8 | return c; 9 | } 10 | -------------------------------------------------------------------------------- /tests/bitcount.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/bitcount.o -------------------------------------------------------------------------------- /tests/char_16_32.cc: -------------------------------------------------------------------------------- 1 | void 2 | foo32 (char32_t *ptr) 3 | { 4 | const char32_t bar = U'á'; 5 | *ptr = bar; 6 | } 7 | 8 | void 9 | foo16 (char16_t *ptr) 10 | { 11 | const char16_t bar = u'á'; 12 | *ptr = bar; 13 | } 14 | -------------------------------------------------------------------------------- /tests/char_16_32.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/char_16_32.o -------------------------------------------------------------------------------- /tests/const_value_block.cc: -------------------------------------------------------------------------------- 1 | // g++ -c -g const_value_block.cc 2 | 3 | template class aaa; 4 | 5 | template class aaa { typedef int Y; }; 6 | template class aaa { typedef long Y; }; 7 | 8 | aaa a0; 9 | aaa a1; 10 | 11 | 12 | template class bbb; 13 | 14 | template class bbb { typedef int Y; }; 15 | template class bbb { typedef long Y; }; 16 | 17 | bbb b0; 18 | bbb b1; 19 | 20 | 21 | template class ccc; 22 | 23 | template class ccc { typedef int Y; }; 24 | template class ccc { typedef long Y; }; 25 | 26 | ccc c0; 27 | ccc c1; 28 | 29 | 30 | template class ddd; 31 | 32 | template class ddd { typedef int Y; }; 33 | template class ddd { typedef long Y; }; 34 | 35 | ddd d0; 36 | ddd d1; 37 | 38 | 39 | template class eee; 40 | 41 | template class eee { typedef int Y; }; 42 | template class eee { typedef long Y; }; 43 | 44 | eee e0; 45 | eee e1; 46 | 47 | 48 | template class fff; 49 | 50 | template class fff { typedef int Y; }; 51 | template class fff { typedef long Y; }; 52 | 53 | fff f0; 54 | fff f1; 55 | 56 | 57 | template class ggg; 58 | 59 | template class ggg { typedef int Y; }; 60 | template class ggg { typedef long Y; }; 61 | 62 | ggg g0; 63 | ggg g1; 64 | -------------------------------------------------------------------------------- /tests/const_value_block.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/const_value_block.o -------------------------------------------------------------------------------- /tests/const_value_on_enum_with_type.cc: -------------------------------------------------------------------------------- 1 | enum N{A}; 2 | templateclass gah{}; 3 | gah meh; 4 | 5 | // Build with GCC a6f19a7c6b. 6 | -------------------------------------------------------------------------------- /tests/const_value_on_enum_with_type.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/const_value_on_enum_with_type.o -------------------------------------------------------------------------------- /tests/const_value_signedness_from_enumerator.cc: -------------------------------------------------------------------------------- 1 | enum N{A}; 2 | templateclass gah{}; 3 | gah meh; 4 | -------------------------------------------------------------------------------- /tests/const_value_signedness_from_enumerator.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/const_value_signedness_from_enumerator.o -------------------------------------------------------------------------------- /tests/const_value_signedness_small_enough.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/const_value_signedness_small_enough.o -------------------------------------------------------------------------------- /tests/const_value_signedness_small_enough.tcl: -------------------------------------------------------------------------------- 1 | # This test case uses dwarf.exp from GDB. 2 | # GDB_SRCPATH=/path/to/gdb/source tclsh const_value_signedness_small_enough.tcl 3 | # gcc -c const_value_signedness_small_enough.s 4 | 5 | source "dwarf.exp" 6 | 7 | Dwarf::assemble "const_value_signedness_small_enough.s" { 8 | build_id 0102030405060708 9 | 10 | cu {is_64 0 version 4 addr_size 8} { 11 | declare_labels a 12 | 13 | DW_TAG_compile_unit {} { 14 | DW_TAG_class_type {} { 15 | DW_TAG_template_value_param { 16 | {DW_AT_type :$a} 17 | {DW_AT_const_value 0 DW_FORM_data1} 18 | } 19 | } 20 | a: DW_TAG_enumeration_type {} { 21 | DW_TAG_enumerator { 22 | {DW_AT_const_value 0 DW_FORM_data1} 23 | } 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/defaulted.cc: -------------------------------------------------------------------------------- 1 | // g++ -c -g defaulted.cc 2 | // Compiled with GCC 7.2.1 3 | struct Foo { 4 | Foo () = default; 5 | } foo {}; 6 | 7 | struct Bar { 8 | Bar (); 9 | }; 10 | 11 | Bar::Bar () = default; 12 | 13 | Bar bar {}; 14 | -------------------------------------------------------------------------------- /tests/defaulted.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/defaulted.o -------------------------------------------------------------------------------- /tests/duplicate-const: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/duplicate-const -------------------------------------------------------------------------------- /tests/dwarf.exp: -------------------------------------------------------------------------------- 1 | set hex "0\[xX\]\[0-9a-fA-F\]+" 2 | set decimal "\[0-9\]+" 3 | set path $::env(GDB_SRCPATH) 4 | set tspath [file join $path gdb testsuite] 5 | set srcdir $tspath 6 | 7 | source [file join $tspath lib dwarf.exp] 8 | -------------------------------------------------------------------------------- /tests/dwz-dupfile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/dwz-dupfile -------------------------------------------------------------------------------- /tests/dwz-dupfile.c: -------------------------------------------------------------------------------- 1 | typedef const volatile unsigned long long int ***W; 2 | 3 | W w; 4 | 5 | int main (void) 6 | { 7 | } 8 | 9 | // gcc -g -c dwz-dupfile.c 10 | // gcc dwz-dupfile.o -o a1.out 11 | // gcc dwz-dupfile.o -o a2.out 12 | // gcc dwz-dupfile.o -o a3.out 13 | // dwz -m dwz-dupfile a{1,2,3}.out 14 | -------------------------------------------------------------------------------- /tests/dwz-partial: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/dwz-partial -------------------------------------------------------------------------------- /tests/dwz-partial.c: -------------------------------------------------------------------------------- 1 | #if A==1 2 | typedef const volatile unsigned long long int ***W; 3 | W w; 4 | 5 | int main (void) 6 | { 7 | } 8 | #elif A==2 9 | typedef const volatile unsigned long long int ***X; 10 | X x; 11 | #elif A==3 12 | typedef const volatile unsigned long long int ***Y; 13 | Y y; 14 | #elif A==4 15 | typedef const volatile unsigned long long int ***Z; 16 | Z z; 17 | #endif 18 | 19 | // gcc -g tests/dwz-partial.c -c -DA=1 -o dwz1.o 20 | // gcc -g tests/dwz-partial.c -c -DA=2 -o dwz2.o 21 | // gcc -g tests/dwz-partial.c -c -DA=3 -o dwz3.o 22 | // gcc -g tests/dwz-partial.c -c -DA=4 -o dwz4.o 23 | // gcc dwz{1,2,3,4}.o 24 | // dwz a.out 25 | -------------------------------------------------------------------------------- /tests/dwz-partial2-1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/dwz-partial2-1 -------------------------------------------------------------------------------- /tests/dwz-partial2-C: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/dwz-partial2-C -------------------------------------------------------------------------------- /tests/dwz-partial2.c: -------------------------------------------------------------------------------- 1 | // The intent behind this test is to have an alt-file with a root DIE 2 | // whose offset is the same as an offset of a non-root DIE from the 3 | // main file. 4 | typedef const volatile unsigned long long int *******W; 5 | typedef const volatile long long int ***X; 6 | 7 | #if A==1 8 | W w1; 9 | 10 | int main (void) 11 | { 12 | } 13 | 14 | #elif A==2 15 | W w2; 16 | X x2; 17 | 18 | #elif A==3 19 | X x3; 20 | 21 | #endif 22 | 23 | // gcc -g dwz-partial2.c -c -DA=1 -o dwz-partial2-1.o 24 | // gcc -g dwz-partial2.c -c -DA=2 -o dwz-partial2-2.o 25 | // gcc -g dwz-partial2.c -c -DA=3 -o dwz-partial2-3.o 26 | // gcc -g dwz-partial2-{1,2,3}.o -o dwz-partial2-1 27 | // gcc -g dwz-partial2-{1,2,3}.o -o dwz-partial2-2 28 | // gcc -g dwz-partial2-{1,2,3}.o -o dwz-partial2-3 29 | // dwz -m dwz-partial2-C dwz-partial2-{1,2,3} 30 | -------------------------------------------------------------------------------- /tests/dwz-partial3-1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/dwz-partial3-1 -------------------------------------------------------------------------------- /tests/dwz-partial3-C: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/dwz-partial3-C -------------------------------------------------------------------------------- /tests/dwz-partial3.c: -------------------------------------------------------------------------------- 1 | // The intent behind this test is to have a file with a root DIE whose 2 | // offset is the same as an offset of a non-root DIE from the altlink 3 | // file. 4 | typedef const volatile unsigned long long int **const**W; 5 | typedef const volatile long long int ***X; 6 | 7 | #if A==1 8 | W w1; 9 | 10 | int main (void) 11 | { 12 | } 13 | 14 | #elif A==2 15 | W w2; 16 | X x2; 17 | 18 | #elif A==3 19 | X x3; 20 | 21 | #endif 22 | 23 | // gcc -g dwz-partial3.c -c -DA=1 -o dwz-partial3-1.o 24 | // gcc -g dwz-partial3.c -c -DA=2 -o dwz-partial3-2.o 25 | // gcc -g dwz-partial3.c -c -DA=3 -o dwz-partial3-3.o 26 | // gcc -g dwz-partial3-{1,2,3}.o -o dwz-partial3-1 27 | // gcc -g dwz-partial3-{1,2,3}.o -o dwz-partial3-2 28 | // gcc -g dwz-partial3-{1,2,3}.o -o dwz-partial3-3 29 | // dwz -m dwz-partial3-C dwz-partial3-{1,2,3} 30 | -------------------------------------------------------------------------------- /tests/dwz-partial4-1.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/dwz-partial4-1.o -------------------------------------------------------------------------------- /tests/dwz-partial4-C: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/dwz-partial4-C -------------------------------------------------------------------------------- /tests/dwz-partial4.tcl: -------------------------------------------------------------------------------- 1 | # This test case uses dwarf.exp from GDB. 2 | # GDB_SRCPATH=/path/to/gdb/source tclsh dwz-partial4.tcl 3 | # gcc -c dwz-partial4-1.s 4 | # gcc -c dwz-partial4-C.s -o dwz-partial4-C 5 | 6 | source "dwarf.exp" 7 | 8 | Dwarf::assemble "dwz-partial4-C.s" { 9 | build_id 0102030405060708 10 | 11 | cu {is_64 0 version 4 addr_size 8} { 12 | partial_unit {} { 13 | subprogram {} { 14 | formal_parameter {} { 15 | } 16 | } 17 | } 18 | } 19 | } 20 | 21 | Dwarf::assemble "dwz-partial4-1.s" { 22 | gnu_debugaltlink "dwz-partial4-C" 0102030405060708 23 | 24 | cu {is_64 0 version 4 addr_size 8} { 25 | compile_unit {} { 26 | structure_type {} {} 27 | structure_type {} {} 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/empty -------------------------------------------------------------------------------- /tests/empty.s: -------------------------------------------------------------------------------- 1 | .file "empty.c" 2 | .text 3 | .Ltext0: 4 | .globl main 5 | .type main, @function 6 | main: 7 | .LFB0: 8 | .file 1 "empty.c" 9 | .loc 1 2 0 10 | .cfi_startproc 11 | pushq %rbp 12 | .cfi_def_cfa_offset 16 13 | .cfi_offset 6, -16 14 | movq %rsp, %rbp 15 | .cfi_def_cfa_register 6 16 | movl %edi, -4(%rbp) 17 | movq %rsi, -16(%rbp) 18 | .loc 1 3 0 19 | movl $0, %eax 20 | .loc 1 4 0 21 | popq %rbp 22 | .cfi_def_cfa 7, 8 23 | ret 24 | .cfi_endproc 25 | .LFE0: 26 | .size main, .-main 27 | .Letext0: 28 | .section .debug_info,"",@progbits 29 | .Ldebug_info0: 30 | .long 0x84 31 | .value 0x3 32 | .long .Ldebug_abbrev0 33 | .byte 0x8 34 | .uleb128 0x1 35 | .long .LASF3 36 | .byte 0x1 37 | .long .LASF4 38 | .long .LASF5 39 | .quad .Ltext0 40 | .quad .Letext0 41 | .long .Ldebug_line0 42 | .byte 0 43 | .section .debug_abbrev,"",@progbits 44 | .Ldebug_abbrev0: 45 | .uleb128 0x1 46 | .uleb128 0x11 47 | .byte 0x0 48 | .uleb128 0x25 49 | .uleb128 0xe 50 | .uleb128 0x13 51 | .uleb128 0xb 52 | .uleb128 0x3 53 | .uleb128 0xe 54 | .uleb128 0x1b 55 | .uleb128 0xe 56 | .uleb128 0x11 57 | .uleb128 0x1 58 | .uleb128 0x12 59 | .uleb128 0x1 60 | .uleb128 0x10 61 | .uleb128 0x6 62 | .byte 0 63 | .byte 0 64 | .section .debug_line,"",@progbits 65 | .Ldebug_line0: 66 | .section .debug_str,"MS",@progbits,1 67 | .LASF5: 68 | .string "/home/petr/proj/dwgrep" 69 | .LASF1: 70 | .string "argv" 71 | .LASF0: 72 | .string "argc" 73 | .LASF4: 74 | .string "empty.c" 75 | .LASF2: 76 | .string "char" 77 | .LASF6: 78 | .string "main" 79 | .LASF3: 80 | .string "GNU C 4.6.3 20120306 (Red Hat 4.6.3-2)" 81 | .ident "GCC: (GNU) 4.6.3 20120306 (Red Hat 4.6.3-2)" 82 | .section .note.GNU-stack,"",@progbits 83 | -------------------------------------------------------------------------------- /tests/entry_dwarf_counts_every_unit_anew.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/entry_dwarf_counts_every_unit_anew.o -------------------------------------------------------------------------------- /tests/entry_dwarf_counts_every_unit_anew.tcl: -------------------------------------------------------------------------------- 1 | # This test case uses dwarf.exp from GDB. 2 | # GDB_SRCPATH=/path/to/gdb/source tclsh entry_dwarf_counts_every_unit_anew.tcl 3 | # gcc -c entry_dwarf_counts_every_unit_anew.s 4 | 5 | source "dwarf.exp" 6 | 7 | Dwarf::assemble "entry_dwarf_counts_every_unit_anew.s" { 8 | build_id 0102030405060708 9 | 10 | cu {is_64 0 version 4 addr_size 8} { 11 | compile_unit {} {} 12 | } 13 | cu {is_64 0 version 4 addr_size 8} { 14 | compile_unit {} {} 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/enum.cc: -------------------------------------------------------------------------------- 1 | enum class e: unsigned { V = -1U } ae = e::V; 2 | enum class f: signed { V = -1 } af = f::V; 3 | -------------------------------------------------------------------------------- /tests/enum.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/enum.o -------------------------------------------------------------------------------- /tests/float_const_value.cc: -------------------------------------------------------------------------------- 1 | namespace NS { 2 | const float fv = 1.5; 3 | const double dv = 1.5; 4 | const long double ldv = 1.5; 5 | } 6 | -------------------------------------------------------------------------------- /tests/float_const_value.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/float_const_value.o -------------------------------------------------------------------------------- /tests/float_const_value.o-armv7hl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/float_const_value.o-armv7hl -------------------------------------------------------------------------------- /tests/float_const_value.o-ppc64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/float_const_value.o-ppc64 -------------------------------------------------------------------------------- /tests/haschildren_childless: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/haschildren_childless -------------------------------------------------------------------------------- /tests/haschildren_childless.s: -------------------------------------------------------------------------------- 1 | .file "x.c" 2 | .text 3 | .Ltext0: 4 | .globl main 5 | .type main, @function 6 | main: 7 | .LFB0: 8 | .file 1 "x.c" 9 | .loc 1 2 0 10 | .cfi_startproc 11 | pushq %rbp 12 | .cfi_def_cfa_offset 16 13 | .cfi_offset 6, -16 14 | movq %rsp, %rbp 15 | .cfi_def_cfa_register 6 16 | .loc 1 3 0 17 | movl $7, %eax 18 | .loc 1 4 0 19 | popq %rbp 20 | .cfi_def_cfa 7, 8 21 | ret 22 | .cfi_endproc 23 | .LFE0: 24 | .size main, .-main 25 | .Letext0: 26 | .section .debug_info,"",@progbits 27 | .Ldebug_info0: 28 | .long 0x50 29 | .value 0x3 30 | .long .Ldebug_abbrev0 31 | .byte 0x8 32 | .uleb128 0x1 33 | .long .LASF0 34 | .byte 0x1 35 | .string "x.c" 36 | .long .LASF1 37 | .quad .Ltext0 38 | .quad .Letext0 39 | .long .Ldebug_line0 40 | .uleb128 0x2 41 | .byte 0x1 42 | .long .LASF2 43 | .byte 0x1 44 | .byte 0x1 45 | .byte 0x1 46 | .long 0x4c 47 | .quad .LFB0 48 | .quad .LFE0 49 | .byte 0x1 50 | .byte 0x9c 51 | .byte 0 52 | .uleb128 0x3 53 | .byte 0x4 54 | .byte 0x5 55 | .string "int" 56 | .byte 0 57 | .section .debug_abbrev,"",@progbits 58 | .Ldebug_abbrev0: 59 | .uleb128 0x1 60 | .uleb128 0x11 61 | .byte 0x1 62 | .uleb128 0x25 63 | .uleb128 0xe 64 | .uleb128 0x13 65 | .uleb128 0xb 66 | .uleb128 0x3 67 | .uleb128 0x8 68 | .uleb128 0x1b 69 | .uleb128 0xe 70 | .uleb128 0x11 71 | .uleb128 0x1 72 | .uleb128 0x12 73 | .uleb128 0x1 74 | .uleb128 0x10 75 | .uleb128 0x6 76 | .byte 0 77 | .byte 0 78 | .uleb128 0x2 79 | .uleb128 0x2e 80 | .byte 1 81 | .uleb128 0x3f 82 | .uleb128 0xc 83 | .uleb128 0x3 84 | .uleb128 0xe 85 | .uleb128 0x3a 86 | .uleb128 0xb 87 | .uleb128 0x3b 88 | .uleb128 0xb 89 | .uleb128 0x27 90 | .uleb128 0xc 91 | .uleb128 0x49 92 | .uleb128 0x13 93 | .uleb128 0x11 94 | .uleb128 0x1 95 | .uleb128 0x12 96 | .uleb128 0x1 97 | .uleb128 0x40 98 | .uleb128 0xa 99 | .byte 0 100 | .byte 0 101 | .uleb128 0x3 102 | .uleb128 0x24 103 | .byte 0 104 | .uleb128 0xb 105 | .uleb128 0xb 106 | .uleb128 0x3e 107 | .uleb128 0xb 108 | .uleb128 0x3 109 | .uleb128 0x8 110 | .byte 0 111 | .byte 0 112 | .byte 0 113 | .section .debug_aranges,"",@progbits 114 | .long 0x2c 115 | .value 0x2 116 | .long .Ldebug_info0 117 | .byte 0x8 118 | .byte 0 119 | .value 0 120 | .value 0 121 | .quad .Ltext0 122 | .quad .Letext0-.Ltext0 123 | .quad 0 124 | .quad 0 125 | .section .debug_line,"",@progbits 126 | .Ldebug_line0: 127 | .section .debug_str,"MS",@progbits,1 128 | .LASF1: 129 | .string "/home/petr/proj/dwgrep" 130 | .LASF2: 131 | .string "main" 132 | .LASF0: 133 | .string "GNU C 4.6.3 20120306 (Red Hat 4.6.3-2)" 134 | .ident "GCC: (GNU) 4.6.3 20120306 (Red Hat 4.6.3-2)" 135 | .section .note.GNU-stack,"",@progbits 136 | -------------------------------------------------------------------------------- /tests/imported-AT_decl_file.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/imported-AT_decl_file.o -------------------------------------------------------------------------------- /tests/imported-AT_decl_file.tcl: -------------------------------------------------------------------------------- 1 | # This test case uses dwarf.exp from GDB. 2 | # 3 | # GDB_SRCPATH=/path/to/gdb/source tclsh imported-AT_decl_file.tcl 4 | # gcc -c imported-AT_decl_file.s 5 | 6 | source "dwarf.exp" 7 | 8 | Dwarf::assemble "imported-AT_decl_file.s" { 9 | build_id 0102030405060708 10 | 11 | declare_labels b; 12 | 13 | cu {is_64 0 version 4 addr_size 8} { 14 | declare_labels a 15 | DW_TAG_compile_unit { 16 | {DW_AT_stmt_list $b DW_FORM_sec_offset} 17 | } { 18 | a: DW_TAG_subprogram { 19 | {DW_AT_decl_file 1 DW_FORM_data1} 20 | } 21 | } 22 | } 23 | 24 | cu {is_64 0 version 4 addr_size 8} { 25 | DW_TAG_compile_unit {} { 26 | DW_TAG_subprogram { 27 | {DW_AT_specification $a DW_FORM_ref_addr} 28 | {DW_AT_name "blah"} 29 | } 30 | } 31 | } 32 | 33 | lines {is_64 0 version 2 addr_size 8} b { 34 | include_dir "foo" 35 | file_name "foo.c" 1 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tests/inconsistent-types: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/inconsistent-types -------------------------------------------------------------------------------- /tests/inconsistent-types.cc: -------------------------------------------------------------------------------- 1 | class foo { 2 | public: 3 | int overload1arg (char); 4 | }; 5 | 6 | 7 | int main () 8 | { 9 | foo foo_instance1; 10 | return 0; 11 | } 12 | 13 | int foo::overload1arg (char arg) { arg = 0; return 2;} 14 | 15 | -------------------------------------------------------------------------------- /tests/nontrivial-types.c: -------------------------------------------------------------------------------- 1 | struct foo {}; 2 | 3 | int blah (struct foo f) { 4 | return 0; 5 | } 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | return blah ((struct foo) {}); 10 | } 11 | -------------------------------------------------------------------------------- /tests/nontrivial-types.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/nontrivial-types.o -------------------------------------------------------------------------------- /tests/nullptr.cc: -------------------------------------------------------------------------------- 1 | struct foo { 2 | int *f; 3 | foo (decltype(nullptr)) : f () {} 4 | } x (nullptr); 5 | -------------------------------------------------------------------------------- /tests/nullptr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/nullptr.o -------------------------------------------------------------------------------- /tests/pointer_const_value.c: -------------------------------------------------------------------------------- 1 | static void foo(void **valp, void *foo) { 2 | *valp = foo; 3 | } 4 | 5 | void foo_wrap(void **valp) { 6 | foo(valp, 0); 7 | } 8 | -------------------------------------------------------------------------------- /tests/pointer_const_value.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/pointer_const_value.o -------------------------------------------------------------------------------- /tests/ptrmember_const_value.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/ptrmember_const_value.o -------------------------------------------------------------------------------- /tests/testfile_const_type: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/testfile_const_type -------------------------------------------------------------------------------- /tests/testfile_const_type.c: -------------------------------------------------------------------------------- 1 | // This file was taken from elfutils. 2 | // gcc -m32 -g -O2 -o const_type const_type.c 3 | 4 | __attribute__((noinline, noclone)) int 5 | f1 (long long d) 6 | { 7 | long long w = d / 0x1234567800000LL; 8 | return w; 9 | } 10 | 11 | int 12 | main () 13 | { 14 | return f1 (4LL) - f1 (4LL); 15 | } 16 | -------------------------------------------------------------------------------- /tests/twocus: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/twocus -------------------------------------------------------------------------------- /tests/twocus1.c: -------------------------------------------------------------------------------- 1 | int foo () { return 2; } 2 | -------------------------------------------------------------------------------- /tests/twocus2.c: -------------------------------------------------------------------------------- 1 | int main (void) { return foo (); } 2 | -------------------------------------------------------------------------------- /tests/typedef.c: -------------------------------------------------------------------------------- 1 | typedef int int_t; 2 | typedef int_t int_t_t; 3 | typedef int_t_t int_t_t_t; 4 | 5 | int_t_t_t a; 6 | -------------------------------------------------------------------------------- /tests/typedef.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/typedef.o -------------------------------------------------------------------------------- /tests/y-mips.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/y-mips.o -------------------------------------------------------------------------------- /tests/y.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pmachata/dwgrep/e01b74fed75c9b81358df467a5d128a388177efd/tests/y.o -------------------------------------------------------------------------------- /version.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2014 Red Hat, Inc. 3 | 4 | This file is free software; you can redistribute it and/or modify 5 | it under the terms of either 6 | 7 | * the GNU Lesser General Public License as published by the Free 8 | Software Foundation; either version 3 of the License, or (at 9 | your option) any later version 10 | 11 | or 12 | 13 | * the GNU General Public License as published by the Free 14 | Software Foundation; either version 2 of the License, or (at 15 | your option) any later version 16 | 17 | or both in parallel, as here. 18 | 19 | dwgrep is distributed in the hope that it will be useful, but 20 | WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | General Public License for more details. 23 | 24 | You should have received copies of the GNU General Public License and 25 | the GNU Lesser General Public License along with this program. If 26 | not, see . */ 27 | 28 | #ifndef VERSION_H 29 | #define VERSION_H 30 | 31 | #define DWGREP_VERSION_MAJOR @DWGREP_MAJOR@ 32 | #define DWGREP_VERSION_MINOR @DWGREP_MINOR@ 33 | 34 | #endif /* VERSION_H */ 35 | --------------------------------------------------------------------------------