use endianity::{Endianity, EndianBuf};
use lookup::{PubStuffParser, LookupEntryIter, DebugLookup, NamesOrTypesSwitch};
use parser::{Format, Result};
use unit::{DebugInfoOffset, parse_debug_info_offset};
use std::ffi;
use std::marker::PhantomData;
use std::rc::Rc;
#[derive(Debug, PartialEq, Eq)]
pub struct PubNamesHeader {
format: Format,
length: u64,
version: u16,
info_offset: DebugInfoOffset,
info_length: u64,
}
#[derive(Debug, Clone)]
pub struct PubNamesEntry<'input> {
offset: u64,
name: &'input ffi::CStr,
header: Rc<PubNamesHeader>,
}
impl<'input> PubNamesEntry<'input> {
pub fn name(&self) -> &'input ffi::CStr {
self.name
}
pub fn info_offset(&self) -> DebugInfoOffset {
self.header.info_offset
}
}
#[derive(Clone, Debug)]
pub struct NamesSwitch<'input, Endian>
where Endian: 'input + Endianity
{
phantom: PhantomData<&'input Endian>,
}
impl<'input, Endian> NamesOrTypesSwitch<'input, Endian> for NamesSwitch<'input, Endian>
where Endian: Endianity
{
type Header = PubNamesHeader;
type Entry = PubNamesEntry<'input>;
type Offset = DebugInfoOffset;
fn new_header(format: Format,
set_length: u64,
version: u16,
offset: DebugInfoOffset,
length: u64)
-> Rc<PubNamesHeader> {
Rc::new(PubNamesHeader {
format: format,
length: set_length,
version: version,
info_offset: offset,
info_length: length,
})
}
fn new_entry(offset: u64,
name: &'input ffi::CStr,
header: &Rc<PubNamesHeader>)
-> PubNamesEntry<'input> {
PubNamesEntry {
offset: offset,
name: name,
header: header.clone(),
}
}
fn parse_offset(input: EndianBuf<Endian>,
format: Format)
-> Result<(EndianBuf<Endian>, Self::Offset)> {
parse_debug_info_offset(input, format)
}
fn format_from(header: &PubNamesHeader) -> Format {
header.format
}
}
pub type DebugPubNames<'input, Endian> = DebugLookup<'input,
Endian,
PubStuffParser<'input,
Endian,
NamesSwitch<'input, Endian>>>;
pub type PubNamesEntryIter<'input, Endian> = LookupEntryIter<'input,
Endian,
PubStuffParser<'input,
Endian,
NamesSwitch<'input,
Endian>>>;