Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Commit 1e279f4

Browse files
emrekultursayEmre Kultursay
authored andcommitted
Add new module search algorithm for Python.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=184720075
1 parent c2da9cb commit 1e279f4

7 files changed

Lines changed: 582 additions & 7 deletions

File tree

src/googleclouddebugger/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,13 @@ def _StartDebugger():
5151
cdbg_native.InitializeModule(_flags)
5252

5353
_hub_client = gcp_hub_client.GcpHubClient()
54-
5554
visibility_policy = _GetVisibilityPolicy()
55+
use_new_module_search = _flags.get('use_new_module_search')
56+
5657
_breakpoints_manager = breakpoints_manager.BreakpointsManager(
57-
_hub_client, visibility_policy)
58+
_hub_client,
59+
visibility_policy,
60+
use_new_module_search=use_new_module_search)
5861

5962
# Set up loggers for logpoints.
6063
capture_collector.SetLogger(logging.getLogger())

src/googleclouddebugger/breakpoints_manager.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,17 @@ class BreakpointsManager(object):
3636
breakpoint updates back to the backend.
3737
data_visibility_policy: An object used to determine the visibiliy
3838
of a captured variable. May be None if no policy is available.
39+
use_new_module_search: If true, the new module search algorithm will be
40+
used.
3941
"""
4042

41-
def __init__(self, hub_client, data_visibility_policy):
43+
def __init__(self,
44+
hub_client,
45+
data_visibility_policy,
46+
use_new_module_search=False):
4247
self._hub_client = hub_client
4348
self.data_visibility_policy = data_visibility_policy
49+
self.use_new_module_search = use_new_module_search
4450

4551
# Lock to synchronize access to data across multiple threads.
4652
self._lock = RLock()
@@ -75,7 +81,11 @@ def SetActiveBreakpoints(self, breakpoints_data):
7581
self._active.update([
7682
(x['id'],
7783
python_breakpoint.PythonBreakpoint(
78-
x, self._hub_client, self, self.data_visibility_policy))
84+
x,
85+
self._hub_client,
86+
self,
87+
self.data_visibility_policy,
88+
self.use_new_module_search))
7989
for x in breakpoints_data
8090
if x['id'] in ids - self._active.viewkeys() - self._completed])
8191

src/googleclouddebugger/imphook.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Support for breakpoints on modules that haven't been loaded yet."""
15+
"""Support for breakpoints on modules that haven't been loaded yet.
16+
17+
This is the old module import hook which:
18+
1. Takes full path of the module with file extension as input.
19+
2. At each (top-level-only) import statement:
20+
a. Uses path to guess all possible names the module may be loaded as.
21+
b. Checks sys.modules if there are any modules loaded with those names,
22+
using exact path match between the __file__ attribute of the module
23+
from sys.modules and the input path.
24+
25+
For the new module import hook, see imphook2.py file.
26+
"""
1627

1728
import os
1829
import sys # Must be imported, otherwise import hooks don't work.
@@ -35,7 +46,7 @@ def AddImportCallback(abspath, callback):
3546
"""Register import hook.
3647
3748
This function overrides the default import process. Then whenever a module
38-
corresponding to source_path is imported, the callback will be invoked.
49+
corresponding to abspath is imported, the callback will be invoked.
3950
4051
A module may be imported multiple times. Import event only means that the
4152
Python code contained an "import" statement. The actual loading and

0 commit comments

Comments
 (0)