use of com.google.security.zynamics.binnavi.debug.models.trace.TraceList in project binnavi by google.
the class PostgreSQLTracesLoader method loadTraces.
/**
* Loads all traces of a view container.
*
* @param provider The connection to the database.
* @param tableName The table name of the view container.
* @param columnName The column name of the view container.
* @param containerId The ID of the view container.
* @param modules List of all modules stored in the database.
*
* @return The loaded traces.
*
* @throws CouldntLoadDataException Thrown if loading the traces failed.
*/
public static IFilledList<TraceList> loadTraces(final AbstractSQLProvider provider, final String tableName, final String columnName, final int containerId, final List<? extends INaviModule> modules) throws CouldntLoadDataException {
Preconditions.checkNotNull(provider, "IE00590: Provider argument can not be null");
Preconditions.checkNotNull(tableName, "IE00591: Table name argument can not be null");
Preconditions.checkNotNull(columnName, "IE00592: Column name argument can not be null");
final String query = "select id, name, description from " + CTableNames.TRACES_TABLE + " join " + tableName + " on " + tableName + ".trace_id = " + CTableNames.TRACES_TABLE + ".id where " + tableName + "." + columnName + " = " + containerId;
final CConnection connection = provider.getConnection();
final IFilledList<TraceList> traces = new FilledList<TraceList>();
try {
final ResultSet resultSet = connection.executeQuery(query, true);
try {
while (resultSet.next()) {
final int traceId = resultSet.getInt("id");
final String name = PostgreSQLHelpers.readString(resultSet, "name");
final String description = PostgreSQLHelpers.readString(resultSet, "description");
final TraceList traceList = new TraceList(traceId, name, description, provider);
loadTraceEvents(connection, traceList, modules);
traces.add(traceList);
}
} finally {
resultSet.close();
}
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
return traces;
}
use of com.google.security.zynamics.binnavi.debug.models.trace.TraceList in project binnavi by google.
the class PostgreSQLTracesLoader method loadTraceEvents.
/**
* Loads the trace events of a trace list from the database.
*
* @param connection The connection to the database.
* @param traceList The trace list whose events are loaded.
* @param modules List of all modules stored in the database.
*
* @throws SQLException Thrown if the trace events could not be loaded.
*/
private static void loadTraceEvents(final CConnection connection, final TraceList traceList, final List<? extends INaviModule> modules) throws SQLException {
final List<List<TraceRegister>> values = loadTraceEventValues(connection, traceList);
final String query = "select tid, module_id, address, type from " + CTableNames.TRACE_EVENT_TABLE + " where trace_id = " + traceList.getId() + " order by position asc";
final ResultSet resultSet = connection.executeQuery(query, true);
int counter = 0;
try {
while (resultSet.next()) {
final long tid = resultSet.getLong("tid");
final int moduleId = resultSet.getInt("module_id");
final INaviModule module = resultSet.wasNull() ? null : findModule(modules, moduleId);
final BreakpointAddress address = new BreakpointAddress(module, new UnrelocatedAddress(PostgreSQLHelpers.loadAddress(resultSet, "address")));
final int event = resultSet.getInt("type");
traceList.addEvent(new TraceEvent(tid, address, TraceEventType.parseInt(event), values.isEmpty() ? new ArrayList<TraceRegister>() : values.get(counter)));
counter++;
}
} finally {
resultSet.close();
}
}
use of com.google.security.zynamics.binnavi.debug.models.trace.TraceList in project binnavi by google.
the class CProject method load.
@Override
public void load() throws CouldntLoadDataException, LoadCancelledException {
synchronized (m_loadReporter) {
if (isLoaded()) {
return;
}
m_isLoading = true;
try {
if (!m_loadReporter.report(ProjectLoadEvents.Starting)) {
throw new LoadCancelledException();
}
if (!m_loadReporter.report(ProjectLoadEvents.LoadingAddressSpaces)) {
throw new LoadCancelledException();
}
final List<CAddressSpace> addressSpaces = m_provider.loadAddressSpaces(this);
for (final CAddressSpace space : addressSpaces) {
space.load();
}
if (!m_loadReporter.report(ProjectLoadEvents.LoadingCallgraphViews)) {
throw new LoadCancelledException();
}
final List<ICallgraphView> userCallgraphs = m_provider.loadCallgraphViews(this);
if (!m_loadReporter.report(ProjectLoadEvents.LoadingFlowgraphViews)) {
throw new LoadCancelledException();
}
final List<IFlowgraphView> userFlowgraphs = m_provider.loadFlowgraphs(this);
if (!m_loadReporter.report(ProjectLoadEvents.LoadingMixedgraphViews)) {
throw new LoadCancelledException();
}
final List<INaviView> userMixedgraphs = m_provider.loadMixedgraphs(this);
if (!m_loadReporter.report(ProjectLoadEvents.LoadingTraces)) {
throw new LoadCancelledException();
}
final List<TraceList> traces = m_provider.loadTraces(this);
final ArrayList<INaviView> views = new ArrayList<INaviView>(userCallgraphs);
views.addAll(userFlowgraphs);
views.addAll(userMixedgraphs);
m_content = new CProjectContent(this, m_listeners, m_provider, addressSpaces, views, new FilledList<TraceList>(traces));
} catch (CouldntLoadDataException | LoadCancelledException e) {
m_isLoading = false;
throw e;
} finally {
m_loadReporter.report(ProjectLoadEvents.Finished);
}
for (final IProjectListener listener : m_listeners) {
try {
listener.loadedProject(this);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
m_isLoading = false;
}
}
use of com.google.security.zynamics.binnavi.debug.models.trace.TraceList in project binnavi by google.
the class PostgreSQLProviderTestSetup method testCreateTraceProject4.
@Test
public void testCreateTraceProject4() throws CouldntSaveDataException {
final INaviProject project = loadProject();
final TraceList trace = getProvider().createTrace(project, "Trace Name", "Trace Description");
assertEquals("Trace Name", trace.getName());
assertEquals("Trace Description", trace.getDescription());
assertEquals(0, trace.getEventCount());
}
use of com.google.security.zynamics.binnavi.debug.models.trace.TraceList in project binnavi by google.
the class PostgreSQLProviderTest method testTraceFunctionsSetDescription1.
@Test
public void testTraceFunctionsSetDescription1() throws CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException {
final INaviProject project = getProvider().createProject("SOME_PROJECT");
getProvider().createTrace(project, "SOME_TRACE", "SOME_TRACE_DESCRIPTION");
project.load();
final TraceList trace = project.getContent().getTraces().get(0);
assertEquals("SOME_TRACE_DESCRIPTION", project.getContent().getTraces().get(0).getDescription());
final String description = "boing boing";
PostgreSQLTraceFunctions.setDescription((AbstractSQLProvider) getProvider(), trace, description);
project.close();
INaviProject project2 = null;
for (final INaviProject cProject : getProvider().loadProjects()) {
if (cProject.getConfiguration().getId() == project.getConfiguration().getId()) {
project2 = cProject;
}
}
getProvider().createTrace(project2, "SOME_TRACE_2", "SOME_TRACE_DESCRIPTION_2");
project2.load();
final TraceList trace2 = project2.getContent().getTraces().get(0);
assertEquals(description, trace2.getDescription());
}
Aggregations