1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2008 by Eran Ifrah
// file name : debugcoredump.cpp
//
// -------------------------------------------------------------------------
// A
// _____ _ _ _ _
// / __ \ | | | | (_) |
// | / \/ ___ __| | ___| | _| |_ ___
// | | / _ \ / _ |/ _ \ | | | __/ _ )
// | \__/\ (_) | (_| | __/ |___| | || __/
// \____/\___/ \__,_|\___\_____/_|\__\___|
//
// F i l e
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#include "manager.h"
#include "project.h"
#include "windowattrmanager.h"
#include "macromanager.h"
#include "pluginmanager.h"
#include "editor_config.h"
#include "globals.h"
#include "debuggermanager.h"
#include "debugcoredumpinfo.h"
#include "debugcoredump.h"
#include <wx/display.h>
#include <wx/filedlg.h>
#include <wx/dirdlg.h>
DebugCoreDumpDlg::DebugCoreDumpDlg(wxWindow* parent)
: DebugCoreDumpDlgBase(parent)
{
// Prevent enormously-long strings from crowding the browse buttons off the screen
wxDisplay display;
int width = display.GetClientArea().GetWidth();
wxSize size(width / 4, -1);
m_Core->SetInitialSize(size);
m_ExeFilepath->SetInitialSize(size);
m_WD->SetInitialSize(size);
SetMaxSize(wxSize(width * 2 / 3, -1));
GetSizer()->Layout();
GetSizer()->Fit(this);
SetName("DebugCoreDumpDlg");
WindowAttrManager::Load(this);
Initialize();
if(m_Core->GetCount() == 0) {
// If there's no known core yet, set focus here so one can be added
m_Core->SetFocus();
} else {
m_buttonDebug->SetFocus();
}
}
void DebugCoreDumpDlg::Initialize()
{
DebugCoreDumpInfo info;
EditorConfigST::Get()->ReadObject(wxT("DebugCoreDumpDlg"), &info);
m_choiceDebuggers->Append(DebuggerMgr::Get().GetAvailableDebuggers());
if(m_choiceDebuggers->GetCount()) {
m_choiceDebuggers->SetSelection(0);
}
if(m_choiceDebuggers->GetCount() > (unsigned int)info.GetSelectedDbg()) {
m_choiceDebuggers->SetSelection(info.GetSelectedDbg());
}
m_Core->Append(info.GetCoreFilepaths());
if(m_Core->GetCount() > 0) {
m_Core->SetSelection(0);
}
m_WD->Append(info.GetWds());
if(m_WD->GetCount() > 0) {
m_WD->SetSelection(0);
}
m_ExeFilepath->Append(info.GetExeFilepaths());
if(m_ExeFilepath->GetCount() > 0) {
m_ExeFilepath->SetSelection(0);
} else {
// determine the executable to debug:
// - If the 'Program' field is set - we use it
// - Else we use the project's output name
wxString activename, conf;
ManagerST::Get()->GetActiveProjectAndConf(activename, conf);
BuildConfigPtr buildConf = clCxxWorkspaceST::Get()->GetProjBuildConf(activename, conf);
if(buildConf) {
// expand all macros with their values
wxString programToDebug = buildConf->GetCommand();
programToDebug.Trim().Trim(false);
if(programToDebug.IsEmpty()) {
programToDebug = buildConf->GetOutputFileName();
}
wxString outputFile =
MacroManager::Instance()->Expand(programToDebug, PluginManager::Get(), activename, conf);
if(m_ExeFilepath->Append(outputFile) != wxNOT_FOUND) {
m_ExeFilepath->SetSelection(0);
}
// determine the working directory
// if we have a working directory set in the project settings, use it (if it is not an
// absolute path, it will be appended to the project's path)
wxString projWD = MacroManager::Instance()->Expand(
buildConf->GetWorkingDirectory(), PluginManager::Get(), activename, conf);
projWD.Trim().Trim(false);
wxString wd;
ProjectPtr proj = ManagerST::Get()->GetProject(activename);
if(proj) {
if(projWD.IsEmpty() || !wxFileName(projWD).IsAbsolute()) {
wxString basePath = proj->GetFileName().GetPath();
wd << basePath << wxFileName::GetPathSeparator();
}
}
wd << projWD;
if(m_WD->Insert(wd, 0) != wxNOT_FOUND) {
m_WD->SetSelection(0);
}
}
}
}
void DebugCoreDumpDlg::OnButtonBrowseCore(wxCommandEvent& event)
{
wxUnusedVar(event);
wxString path, ans;
wxFileName fn(GetCore());
if(fn.FileExists()) {
// Use the serialised path as the wxFileSelector default path
path = fn.GetPath();
} else {
// Otherwise use any working dir entry, which might just have been altered
path = GetWorkingDirectory();
}
ans = wxFileSelector(_("Select core dump:"), path);
if(!ans.empty()) {
m_Core->Insert(ans, 0);
m_Core->SetSelection(0);
}
}
void DebugCoreDumpDlg::OnButtonBrowseExe(wxCommandEvent& event)
{
wxUnusedVar(event);
wxString path, ans;
wxFileName fn(GetExe());
if(fn.FileExists()) {
// Use the serialised path as the wxFileSelector default path
path = fn.GetPath();
} else {
// Otherwise use any working dir entry, which might just have been altered
path = GetWorkingDirectory();
}
ans = wxFileSelector(_("Select file:"), path);
if(!ans.empty()) {
m_ExeFilepath->Insert(ans, 0);
m_ExeFilepath->SetSelection(0);
}
}
void DebugCoreDumpDlg::OnButtonBrowseWD(wxCommandEvent& event)
{
wxUnusedVar(event);
wxString ans, path(GetWorkingDirectory());
if(!wxFileName::DirExists(path)) {
path = wxGetCwd();
}
ans = wxDirSelector(_("Select working directory:"), path);
if(!ans.empty()) {
m_WD->Insert(ans, 0);
m_WD->SetSelection(0);
}
}
void DebugCoreDumpDlg::OnButtonCancel(wxCommandEvent& event)
{
wxUnusedVar(event);
EndModal(wxID_CANCEL);
}
void DebugCoreDumpDlg::OnButtonDebug(wxCommandEvent& event)
{
wxUnusedVar(event);
// save values
const size_t MAX_NO_ITEMS = 10;
DebugCoreDumpInfo info;
info.SetCoreFilepaths(ReturnWithStringPrepended(m_Core->GetStrings(), GetCore(), MAX_NO_ITEMS));
info.SetExeFilepaths(ReturnWithStringPrepended(m_ExeFilepath->GetStrings(), GetExe(), MAX_NO_ITEMS));
info.SetWDs(ReturnWithStringPrepended(m_WD->GetStrings(), GetWorkingDirectory(), MAX_NO_ITEMS));
info.SetSelectedDbg(m_choiceDebuggers->GetSelection());
EditorConfigST::Get()->WriteObject(wxT("DebugCoreDumpDlg"), &info);
EndModal(wxID_OK);
}
void DebugCoreDumpDlg::OnDebugBtnUpdateUI(wxUpdateUIEvent& event)
{
// gdb needs both a core and an exe for useful debugging
event.Enable(!GetCore().empty() && !GetExe().empty());
}
|