bindings-bfd-1.0.0: Bindings for libbfd, a library of the GNU `binutils'

Bindings.Bfd

Contents

Description

This is the top-level module containing operations that can be performed on a Binary Format Descriptor (BFD). A BFD is opened on the binary file to be queried/manipulated and serves an opaque pointer.

Synopsis

Types

data Bfd Source

The opaque pointer to the Binary File Descriptor.

Instances

Initialization

initialize :: IO ()Source

Initialize the library. You need to call initialize once, before using any of the functions in this library.

File Operations

targetsAndFormatsSource

Arguments

:: FilePath

file to query

-> IO [(TargetName, Format)] 

Returns a list of tuples representing the possible combinations of TargetName and Format that are valid for this file on this platform.

Possible Exceptions: Same as open.

openSource

Arguments

:: FilePath

file to open

-> Maybe TargetName

target

-> String

open mode ("r", "r+", "w", "w+", "a", "a+")

-> IO Bfd 

Opens the file FilePath with the given target TargetName and open mode (as defined by the Unix fopen(3) function) and returns a Bfd object on success. FIXME: and marks it cacheable.

If the target is Nothing then the environment variable GNUTARGET is checked for a target name; if this is NULL or not defined then it chooses the the default target if set (see setDefault) and sets an internal flag in the Bfd object indicating that the target was defaulted (see isTargetDefaulted), or if not set, the first entry in the target list for the platform. Passing the string "default" as the TargetName or setting the environment variable to "default" also causes the above behavior.

Important: Before you use the returned Bfd object from a file you have opened, you must call checkFormat to 1) validate that the supplied TargetName is appropriate for the opened file, and 2) set the Format for the Bfd. So for most intents and purposes, opening a file is a two-step process.

Possible Exceptions: NoMemory (if any allocation fails), SystemCall (if open failed), and InvalidTarget (if supplied target is unknown).

close :: Bfd -> IO BoolSource

Close a Bfd and if all went well, return True. If the Bfd was open for writing, then pending operations are completed and the file written out and closed. If the created file is executable, then chmod(3) is called to mark it as such.

closeAllDone :: Bfd -> IO BoolSource

Close a Bfd and if all went well, return True. Differs from close in that it does not complete any pending operations. This function would be used if the application had just used a Bfd for swapping and didn't want to use any of the writing code. If the created file is executable, then chmod(3) is called to mark it as such.

Setting the Format

checkFormat :: Bfd -> Format -> IO BoolSource

The second part of opening a file (see open). Validates that the TargetName is appropriate for the opened file and if not, silently picks a more suitable TargetName, and also sets the Format of the Bfd object representing the opened file.

Important: You must call this function before using the vast majority of these functions operating on the Bfd as it updates critical data structures.

Possible Exceptions: InvalidOperation (if the file was opened write-only),

Attributes

getDisasm :: Bfd -> IO DisasmSource

Returns the disassembler associated with the Bfd.

getFilename :: Bfd -> IO FilePathSource

Returns the FilePath of the file associated with the Bfd.

getFlags :: Bfd -> IO [Flags]Source

Returns a List of the Bfds set Flags.

getFormat :: Bfd -> IO FormatSource

Returns the Format of the Bfd.

getHasMap :: Bfd -> IO BoolSource

Returns True if the Bfd has an archive map. Otherwise False.

getIsCacheable :: Bfd -> IO BoolSource

Returns True if the Bfd is cacheable. Otherwise False.

getIsThinArchive :: Bfd -> IO BoolSource

Returns True if the Bfd is a thin archive. Otherwise False.

getMyArchive :: Bfd -> IO (Maybe Bfd)Source

Returns either a Bfd or Nothing. FIXME

Note: Do not pass the returned Bfd to close or closeAllDone or a memory leak will occur.

getTarget :: Bfd -> IO TargetSource

Returns the Target of the Bfd.

For Object Files

getStartAddress :: Bfd -> IO VmaSource

Return the start address. Only valid for Object files.

getSymbolCount :: Bfd -> IO IntSource

Return the symbol count used for input and output. Only valid for Object files. FIXME: returns 0 when there are symbols and in main/main too!

Sections

getSectionCount :: Bfd -> IO IntSource

Returns the number of Sections in the Bfd.

Symbol Tables

Relocations

Internal

data Bfd' Source

Instances