[lldb-dev] Difficulty in using target.source-map to map source files

2017-08-21 Thread karnajit wangkhem via lldb-dev
Hi All,

Below is a sample example, where target.source-map seems to have a
limitation. The limitation seems to be because
1. lldb does not have an equivalent command like directory in gdb
2. target.source-map does not accept multiple mapping entries. I checked
this only with freebsd.

(lldb) settings show target.source-map
target.source-map (path-map) =
[0] "/home/karnajitw/lldb_test_execs/test_source_line1" ->
"/u/test/test_source_line1"

3. Haven't checked in the code yet, but if we see the mappings of scenario
1, they all point to a single real path
/home/karnajitw/lldb_test_execs/test_source_line1.
But looks like the mapping logic only considers strings into account. But,
at the same time, I am not claiming that they should be interpreted as path
from a different machine during the mapping.

I want to check on this issue in-depth. But before that, want to confirm if
this is real issue or there are other ways to deal these scenarios which I
am not aware of?

I am referring below link for the lldb commands.
https://lldb.llvm.org/lldb-gdb.html

1. First scenario: Different souce file path representation

[/home/karnajitw/lldb_test_execs/test_source_line1] $ clang -O0 -g
/home/karnajitw/lldb_test_execs///test_source_line1/main.c
/home/karnajitw/lldb_test_execs/../lldb_test_execs/test_source_line1/a/ainc.c
/home/karnajitw/lldb_test_execs/test_source_line1/a/b/binc.c

Machine 1: /home/karnajitw/lldb_test_execs/test_source_line1 -> Machine 2:
/u/test/test_source_line1

test_source_line1
|-- a
|   |-- ainc.c
|   |-- ainc.h
|   `-- b
|   |-- binc.c
|   `-- binc.h
|-- a.out
`-- main.c

% ./lldb test_source_line1/a.out

(lldb) target create "test_source_line1/a.out"
Current executable set to 'test_source_line1/a.out' (x86_64).
(lldb) l main
File: /home/karnajitw/lldb_test_execs///test_source_line1/main.c
(lldb) l afn
File: /home/karnajitw/lldb_test_execs/../lldb_test_execs/test_sour
ce_line1/a/ainc.c
(lldb) l bfn
File: /home/karnajitw/lldb_test_execs/test_source_line1/a/b/binc.c

(lldb) settings set target.source-map
/home/karnajitw/lldb_test_execs///test_source_line1
/u/test/test_source_line1

(lldb) l main
File: /home/karnajitw/lldb_test_execs///test_source_line1/main.c
   1#include "a/ainc.h"
   2
   3int main()
   4{
   5  afn();
   6
   7  bfn();
   8
   9  return 0;
   10   }
(lldb) l afn
File: /home/karnajitw/lldb_test_execs/../lldb_test_execs/test_sour
ce_line1/a/ainc.c
(lldb) l bfn
File: /home/karnajitw/lldb_test_execs/test_source_line1/a/b/binc.c

(lldb) settings set target.source-map /home/karnajitw/lldb_test_exec
s/../lldb_test_execs/test_source_line1 /u/test/test_source_line1

(lldb) l main
File: /home/karnajitw/lldb_test_execs///test_source_line1/main.c
(lldb) l afn
File: /home/karnajitw/lldb_test_execs/../lldb_test_execs/test_sour
ce_line1/a/ainc.c
   1#include 
   2#include "ainc.h"
   3
   4void afn()
   5{
   6  printf("Hello this is afn...\n");
   7}
(lldb) l bfn
File: /home/karnajitw/lldb_test_execs/test_source_line1/a/b/binc.c

(lldb) settings set target.source-map
/home/karnajitw/lldb_test_execs/test_source_line1
/u/test/test_source_line1

(lldb) l main
File: /home/karnajitw/lldb_test_execs///test_source_line1/main.c
(lldb) l afn
File: /home/karnajitw/lldb_test_execs/../lldb_test_execs/test_sour
ce_line1/a/ainc.c
(lldb) l bfn
File: /home/karnajitw/lldb_test_execs/test_source_line1/a/b/binc.c
   1#include 
   2#include "binc.h"
   3
   4void bfn()
   5{
   6  printf("Hello this is bfn...\n");
   7}

2. Scenario 2: Deep directory structure

/obj/a/b/c/d/e/app/sub/../../../../../../../../src/a/b/
c/d/e/app/sub/file
/obj/a/b/c/d/e/app/../../../../../../../src/a/b/c/d/e/app/file

- If we carry the copy the source file to machine 2, we cannot easily map
the source file without creating dummy /obj/a/b/c/d/e/f/g.

3. Scenario 3: External libraries
- I haven't exactly tested this yet. But I belive in scenario too we might
need to change the source-map.

Please look into this and guide me for the same.

Regards,
Karan
___
lldb-dev mailing list
lldb-dev@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev


Re: [lldb-dev] Difficulty in using target.source-map to map source files

2017-08-24 Thread karnajit wangkhem via lldb-dev
Hi Jim,

Thanks for the valuable reply. Please find my comments inline.

Regards,
Karan

On Wed, Aug 23, 2017 at 12:32 AM, Jim Ingham  wrote:

>
> > On Aug 21, 2017, at 12:02 PM, karnajit wangkhem via lldb-dev <
> lldb-dev@lists.llvm.org> wrote:
> >
> > Hi All,
> >
> > Below is a sample example, where target.source-map seems to have a
> limitation. The limitation seems to be because
> > 1. lldb does not have an equivalent command like directory in gdb
>
> The gdb "dir" command seemed always to be more annoying than useful in
> real situations.  If your project had any complexity in the directory
> structure you ended up having to add dir commands for all the
> subdirectories, which got tedious quickly.  Since you pretty much always
> move your sources around rigidly, "source maps" are a more natural way to
> specify this.
>
> Note, we could add a recursive "dir" command, but you can't do the
> simpleminded recursive search or you'll mess up when the sources have same
> named files in different directories.  Because of this, again the source
> maps seem more suited.
>
>
-- Really a good info to know. Thanks!


> > 2. target.source-map does not accept multiple mapping entries. I checked
> this only with freebsd.
> >
> > (lldb) settings show target.source-map
> > target.source-map (path-map) =
> > [0] "/home/karnajitw/lldb_test_execs/test_source_line1" ->
> "/u/test/test_source_line1"
>
> That is not correct:
>
> (lldb) settings set target.source-map /some/source/path /tmp
> /some/other/source/path /tmp
> (lldb) settings show target.source-map
> target.source-map (path-map) =
> [0] "/some/source/path" -> "/tmp"
> [1] "/some/other/source/path" -> "/tmp"
>
> or
>
> (lldb) set set target.source-map /some/source/path /tmp
> (lldb) set append target.source-map /some/other/source/path /tmp
> (lldb) set show target.source-map
> target.source-map (path-map) =
> [0] "/some/source/path" -> "/tmp"
> [1] "/some/other/source/path" -> "/tmp"
>

- Thanks! This helped.


> >
> > 3. Haven't checked in the code yet, but if we see the mappings of
> scenario 1, they all point to a single real path
> /home/karnajitw/lldb_test_execs/test_source_line1. But looks like the
> mapping logic only considers strings into account. But, at the same time, I
> am not claiming that they should be interpreted as path from a different
> machine during the mapping.
> >
>
> I'm not sure what you mean here.  lldb does what it can to unwind the
> source path, but it doesn't assume that those paths actually exist locally,
> so the most it can do is remove redundant "/"-s and "/./"-s and unwind
> ".."-s.  We do this before most source path comparisons (it's part of the
> FileSpec Equals method).  We've been tinkering with this over time so make
> sure you are using a recent version of lldb.  If there are places where we
> don't do this, then that's easily fixed.
>
>
- Your answer is in line with what I wanted to know. My lldb should be
quite recent. But I used it only for freebsd currently.

% ./lldb --version
lldb version 5.0.0 (http://llvm.org/svn/llvm-project/lldb/trunk revision
305778)
  clang revision 305546
  llvm revision 305548


>
> > I want to check on this issue in-depth. But before that, want to confirm
> if this is real issue or there are other ways to deal these scenarios which
> I am not aware of?
> >
> > I am referring below link for the lldb commands.
> > https://lldb.llvm.org/lldb-gdb.html
> >
> > 1. First scenario: Different souce file path representation
> >
> > [/home/karnajitw/lldb_test_execs/test_source_line1] $ clang -O0 -g
> /home/karnajitw/lldb_test_execs///test_source_line1/main.c
> /home/karnajitw/lldb_test_execs/../lldb_test_execs/test_source_line1/a/ainc.c
> /home/karnajitw/lldb_test_execs/test_source_line1/a/b/binc.c
> >
> > Machine 1: /home/karnajitw/lldb_test_execs/test_source_line1 -> Machine
> 2: /u/test/test_source_line1
> >
> > test_source_line1
> > |-- a
> > |   |-- ainc.c
> > |   |-- ainc.h
> > |   `-- b
> > |   |-- binc.c
> > |   `-- binc.h
> > |-- a.out
> > `-- main.c
> >
> > % ./lldb test_source_line1/a.out
> >
> > (lldb) target create "test_source_line1/a.out"
> > Current executable set to 'test_source_line1/a.out' (x86_64).
> > (lldb) l main
> > File: /home/karnajitw/lldb_test_execs///test_source_line1/main.c
> > (lldb) l afn
>

Re: [lldb-dev] Difficulty in using target.source-map to map source files

2017-08-28 Thread karnajit wangkhem via lldb-dev
Thanks Jim for the help. I would definitely like to work on this PR soon.

Filed the PR here
https://bugs.llvm.org/show_bug.cgi?id=34341

Regards,
Karan

On Thu, Aug 24, 2017 at 11:17 PM, Jim Ingham  wrote:

>
> > On Aug 24, 2017, at 10:06 AM, karnajit wangkhem 
> wrote:
> >
> > Hi Jim,
> >
> > Thanks for the valuable reply. Please find my comments inline.
> >
> > Regards,
> > Karan
> >
> > On Wed, Aug 23, 2017 at 12:32 AM, Jim Ingham  wrote:
> >
> > > On Aug 21, 2017, at 12:02 PM, karnajit wangkhem via lldb-dev <
> lldb-dev@lists.llvm.org> wrote:
> > >
> > > Hi All,
> > >
> > > Below is a sample example, where target.source-map seems to have a
> limitation. The limitation seems to be because
> > > 1. lldb does not have an equivalent command like directory in gdb
> >
> > The gdb "dir" command seemed always to be more annoying than useful in
> real situations.  If your project had any complexity in the directory
> structure you ended up having to add dir commands for all the
> subdirectories, which got tedious quickly.  Since you pretty much always
> move your sources around rigidly, "source maps" are a more natural way to
> specify this.
> >
> > Note, we could add a recursive "dir" command, but you can't do the
> simpleminded recursive search or you'll mess up when the sources have same
> named files in different directories.  Because of this, again the source
> maps seem more suited.
> >
> >
> > -- Really a good info to know. Thanks!
> >
> > > 2. target.source-map does not accept multiple mapping entries. I
> checked this only with freebsd.
> > >
> > > (lldb) settings show target.source-map
> > > target.source-map (path-map) =
> > > [0] "/home/karnajitw/lldb_test_execs/test_source_line1" ->
> "/u/test/test_source_line1"
> >
> > That is not correct:
> >
> > (lldb) settings set target.source-map /some/source/path /tmp
> /some/other/source/path /tmp
> > (lldb) settings show target.source-map
> > target.source-map (path-map) =
> > [0] "/some/source/path" -> "/tmp"
> > [1] "/some/other/source/path" -> "/tmp"
> >
> > or
> >
> > (lldb) set set target.source-map /some/source/path /tmp
> > (lldb) set append target.source-map /some/other/source/path /tmp
> > (lldb) set show target.source-map
> > target.source-map (path-map) =
> > [0] "/some/source/path" -> "/tmp"
> > [1] "/some/other/source/path" -> "/tmp"
> >
> > - Thanks! This helped.
> >
> > >
> > > 3. Haven't checked in the code yet, but if we see the mappings of
> scenario 1, they all point to a single real path 
> /home/karnajitw/lldb_test_execs/test_source_line1.
> But looks like the mapping logic only considers strings into account. But,
> at the same time, I am not claiming that they should be interpreted as path
> from a different machine during the mapping.
> > >
> >
> > I'm not sure what you mean here.  lldb does what it can to unwind the
> source path, but it doesn't assume that those paths actually exist locally,
> so the most it can do is remove redundant "/"-s and "/./"-s and unwind
> ".."-s.  We do this before most source path comparisons (it's part of the
> FileSpec Equals method).  We've been tinkering with this over time so make
> sure you are using a recent version of lldb.  If there are places where we
> don't do this, then that's easily fixed.
> >
> >
> > - Your answer is in line with what I wanted to know. My lldb should be
> quite recent. But I used it only for freebsd currently.
> >
> > % ./lldb --version
> > lldb version 5.0.0 (http://llvm.org/svn/llvm-project/lldb/trunk
> revision 305778)
> >   clang revision 305546
> >   llvm revision 305548
> >
> >
> > > I want to check on this issue in-depth. But before that, want to
> confirm if this is real issue or there are other ways to deal these
> scenarios which I am not aware of?
> > >
> > > I am referring below link for the lldb commands.
> > > https://lldb.llvm.org/lldb-gdb.html
> > >
> > > 1. First scenario: Different souce file path representation
> > >
> > > [/home/karnajitw/lldb_test_execs/test_source_line1] $ clang -O0 -g
> /home/karnajitw/lldb_test_execs///test_source_line1/main.c
> /home/karnajitw/lldb_test_execs/../lldb_test_execs/test_source_line1/a/ainc.c
&

Re: [lldb-dev] Difficulty in using target.source-map to map source files

2017-08-28 Thread karnajit wangkhem via lldb-dev
Thanks for the info. I will keep that in mind.

On Mon, Aug 28, 2017 at 11:05 PM, Jim Ingham  wrote:

> That will be great!  Last time we were more aggressive about normalizing
> paths we caused a decent performance regression by normalizing all the
> paths every time we did a file-name compare for setting breakpoints.  If
> you look at FileSpec::Equal we added some "is it worth doing this work"
> preparatory work.  I don't know where you'll find the additional places
> this needed to be done, but it's worth keeping an eye out for not putting
> GetNormalizedPath on a hot path.
>
> Jim
>
>
>
> > On Aug 28, 2017, at 1:19 AM, karnajit wangkhem 
> wrote:
> >
> > Thanks Jim for the help. I would definitely like to work on this PR soon.
> >
> > Filed the PR here
> > https://bugs.llvm.org/show_bug.cgi?id=34341
> >
> > Regards,
> > Karan
> >
> > On Thu, Aug 24, 2017 at 11:17 PM, Jim Ingham  wrote:
> >
> > > On Aug 24, 2017, at 10:06 AM, karnajit wangkhem 
> wrote:
> > >
> > > Hi Jim,
> > >
> > > Thanks for the valuable reply. Please find my comments inline.
> > >
> > > Regards,
> > > Karan
> > >
> > > On Wed, Aug 23, 2017 at 12:32 AM, Jim Ingham 
> wrote:
> > >
> > > > On Aug 21, 2017, at 12:02 PM, karnajit wangkhem via lldb-dev <
> lldb-dev@lists.llvm.org> wrote:
> > > >
> > > > Hi All,
> > > >
> > > > Below is a sample example, where target.source-map seems to have a
> limitation. The limitation seems to be because
> > > > 1. lldb does not have an equivalent command like directory in gdb
> > >
> > > The gdb "dir" command seemed always to be more annoying than useful in
> real situations.  If your project had any complexity in the directory
> structure you ended up having to add dir commands for all the
> subdirectories, which got tedious quickly.  Since you pretty much always
> move your sources around rigidly, "source maps" are a more natural way to
> specify this.
> > >
> > > Note, we could add a recursive "dir" command, but you can't do the
> simpleminded recursive search or you'll mess up when the sources have same
> named files in different directories.  Because of this, again the source
> maps seem more suited.
> > >
> > >
> > > -- Really a good info to know. Thanks!
> > >
> > > > 2. target.source-map does not accept multiple mapping entries. I
> checked this only with freebsd.
> > > >
> > > > (lldb) settings show target.source-map
> > > > target.source-map (path-map) =
> > > > [0] "/home/karnajitw/lldb_test_execs/test_source_line1" ->
> "/u/test/test_source_line1"
> > >
> > > That is not correct:
> > >
> > > (lldb) settings set target.source-map /some/source/path /tmp
> /some/other/source/path /tmp
> > > (lldb) settings show target.source-map
> > > target.source-map (path-map) =
> > > [0] "/some/source/path" -> "/tmp"
> > > [1] "/some/other/source/path" -> "/tmp"
> > >
> > > or
> > >
> > > (lldb) set set target.source-map /some/source/path /tmp
> > > (lldb) set append target.source-map /some/other/source/path /tmp
> > > (lldb) set show target.source-map
> > > target.source-map (path-map) =
> > > [0] "/some/source/path" -> "/tmp"
> > > [1] "/some/other/source/path" -> "/tmp"
> > >
> > > - Thanks! This helped.
> > >
> > > >
> > > > 3. Haven't checked in the code yet, but if we see the mappings of
> scenario 1, they all point to a single real path 
> /home/karnajitw/lldb_test_execs/test_source_line1.
> But looks like the mapping logic only considers strings into account. But,
> at the same time, I am not claiming that they should be interpreted as path
> from a different machine during the mapping.
> > > >
> > >
> > > I'm not sure what you mean here.  lldb does what it can to unwind the
> source path, but it doesn't assume that those paths actually exist locally,
> so the most it can do is remove redundant "/"-s and "/./"-s and unwind
> ".."-s.  We do this before most source path comparisons (it's part of the
> FileSpec Equals method).  We've been tinkering with this over time so make
> sure you are using a recent version of lldb.  If there are places where w