svaante / dape

Debug Adapter Protocol for Emacs
GNU General Public License v3.0
501 stars 34 forks source link

lldb-dap runs my program but it doesn't stop at breakpoints #151

Closed lanceberge closed 2 months ago

lanceberge commented 2 months ago

steps to reproduce

I'm using the default dape-configs running lldb-dap.

I ran it on this file:

average_contiguous_subarray.cpp

#include <iostream>
#include <stdexcept>
#include <vector>

using namespace std;

/*
Find the average of all contiguous subarrays in arr
*/
vector<double> findAverages(int K, const vector<int> &arr) {
  double sum = 0;
  vector<double> result(arr.size() - K + 1);
  int l = 0;
  int r = 0;

  if (K > arr.size()) {
    throw invalid_argument("K cannot be larger than arr.size");
  }

  for (r = 0; r < K; ++r) {
    sum += arr[r];
  }

  result[0] = sum / K;

  for (int i = 1; i < result.size(); ++i) {
    sum -= arr[l];
    sum += arr[r];

    l += 1;
    r += 1;

    result[i] = sum / K;
  }

  return result;
}

int main() {
  vector<double> result =
      findAverages(5, vector<int>{1, 3, 2, 6, -1, 4, 1, 8, 2});

  for (auto &num : result) {
    cout << num << " ";
  }

  cout << endl;
  return 0;
}

Compile with g++-14 average_contiguous_subarray.cpp -std=c++20 (This is on a Mac with M1)

I had to (add-to-list 'exec-path "/opt/homebrew/opt/llvm/bin") - but it's finding the executable so this shouldn't (?) be a problem.

Set a breakpoint on int main() { with M-x dape-breakpoint-toggle

Then M-x dape and use lldb-dap

Screenshot 2024-09-13 at 6 22 02 PM

It runs the program, shows the output, but doesn't stop at the breakpoint. It also shows the breakpoint on the left in the line-number fringe and in the dape breakpoint window

Here's my *dape-connection-events*:


----------b---y---e---b---y---e----------

----------b---y---e---b---y---e----------

----------b---y---e---b---y---e----------
svaante commented 2 months ago

Hey!

Have you compiled you program with -g "Generate debug information"?

If that does not work set (setq dape-debug t) (does not take affect until next debugging session) then resubmit your *dape-connection events* buffer.

lanceberge commented 2 months ago

Amazing, thank you! This got it to work