<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58360>58360</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [lldb] Setting breakpoint by basename doesn't resolve if function name is a CPlusPlusParser keyword
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            lldb
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Michael137
      </td>
    </tr>
</table>

<pre>
    Example program:
```
$ cat keyword.cpp 
template<typename U>
struct Foo {
    template<typename T>
    void import() {}
};

int main() {
    Foo<double> f;
    f.import<int>();
}

$ ./bin/lldb a.out
(lldb) target create "a.out"
Current executable set to 'a.out' (arm64).
(lldb) br se -n import
Breakpoint 1: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) br se -r import
Breakpoint 2: 43 locations.
(lldb) 
```
This is on a Mac with lldb built from top-of-tree (as of `4ba360d499f6169d62a9535438b3cf34337ffc67`).

This regressed with `f968bd77bbcf142afdb74750e53485b044de3e5f`, where we made the symbol lookup for `eFunctionNameTypeFull` stricter. The patch itself seems fine, it simply exposed a bug in breakpoint resolution
with reserved keywords.

**Details**

The `import` identifier is a reserved keyword in the eyes of the `CPlusPlusLanguage`/`CPlusPlusNameParser` plugin. This means that the `eFunctionNameTypeAuto` (used when creating a breakpoint) gets turned into a `eFunctionNameTypeFull`, which after the commit mentioned above requires that the mangled name matches the symbol search name (in `DWARFIndex::ProcessFunctionDIE`). The relevant code block that resolves the name_type_mask is the following:

```
Module::LookupInfo::LookupInfo(ConstString name,               
                               FunctionNameType name_type_mask,
                               LanguageType language)

CPlusPlusLanguage::MethodName cpp_method(name);                           
basename = cpp_method.GetBasename();                                      
if (basename.empty()) {                                                   
  if (CPlusPlusLanguage::ExtractContextAndIdentifier(name_cstr, context,  
                                                     basename))           
    m_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
  else                                                                    
    m_name_type_mask |= eFunctionNameTypeFull;  <<<< ExtractContextAndIdentifier fails to parse “import” because it’s a keyword         
```

Then the breakpoint resolver calls into `DWARFIndex::ProcessFunctionDIE` to find symbols matching the basename the user specified. But since the name_type_mask is `eFunctionNameTypeFull` we try to compare the mangled name against the non-mangled identifier, which call the DIE callback (whereas previously it would have):
```
bool DWARFIndex::ProcessFunctionDIE(
...
// In case of a full match, we just insert everything we find.             
if (name_type_mask & eFunctionNameTypeFull && die.GetMangledName() == name)
  return callback(die);  <<< Will now never be called
...                 
```

The real bug here is simply that the type_mask should be set to `eFunctionNameTypeMethod | eFunctionNameTypeBase` when constructing `Module::LookupInfo::LookupInfo`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytV8tym0oQ_Rq0mTIl8xQLLfxSylVxKnWTVJauARqJGBjdYbCtv7-nZxCyLdnx4lL4ATPTffr0k1yVu-XNs2y3DYmtVmstWy-88ObX3vzCS-bj7R6DSBTSiAfaPSld-sV2K9yKIZyXhrzwyuy21MmWxC8vvHGrvdFDYcRKKeGll-6dwHXq1M_pFO94VHUp6nartPGChRdkVkB6PeLBP-Eoz_2uOyNaWXcvNk-yoB6KSjXkDTTeiGo6y6uVP6oJryCEQVgRB_mT0okK3wtWOetaNU2ZC-mrwexXF_yKIRip12REoQmGCi8I3LYgcDuvBq0JoOmZisFIQBM9thswFaTj1hT_L6RukwgC_SMNucYRcdbtebLrl9D3sFXMxzncKTolGgXf1arrWRzYLutufRD4--Kfb7ffvvBe8auzQABCU6-aR4KOSRzeym4nZGEG2RyEvotLv4crYF1R-JGIk1H4c1P3ArfqhBR3shBPtdkI64J8qBsjKq1awNyeqerMaCJLH_ZXAjKiXIbJvIyyrErOk6xMApnFYRyFizwsqjAKw7SqiiRldQe2D4o1rUFKT6VTi21VlizyMk3zvKjOo0BWZZ5GaTynOIwWcT6PopJCiisr8Uo8bUiTeCLEaQmON3D4rs0VU6kehq2olGaptBq6gm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